javascript - for/while loop for reading user input -


i'm kinda new programming , got question in quiz. need write javascript program read 10 positive values user, , sum multiples of 3 , 5.

i couldn't finish code. help?

var x = new array (); var total; x.push(parsefloat(window.prompt("enter value",""),)); (x.length<=10; i=0; i<10; i++) {     total += x[i] }  else{     document.write(total); } 

you need put prompt function inside loop , add check if number multiply 3 or 5.

var total; (var i=0; i<10; i++) {     var num = parsefloat(window.prompt("enter value",""));     if (num % 3 == 0 || num % 5 == 0) {         total += num;     } }       document.write(total); 

update:

var total; var = 0; while (i<10) {     var num = parsefloat(window.prompt("enter value",""));     if (num >= 0 && (num % 3 == 0 || num % 5 == 0)) {         total += num;         i++;     } }       document.write(total); 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

c++ - No viable overloaded operator for references a map -

java - UML - How would you draw a try catch in a sequence diagram? -