For loop won't end. Don't know why -
i'm writing loop project prompts user input number , keeps prompting, continually adding numbers up. when string introduced, loop should stop. i've done while loop, project states must loop also. problem prompt keeps running when 'a = false'. explain javascript's thinking process? want understand why keeps running through loop though condition isn't met. thank you
var addsequence2 = function() { var total = 0; var a; (; = true; ) { var input = prompt("your current score " +total+ "\n" + "next number..."); if (!isnan(input)) { = true; total = +total + +input; } else if (isnan(input)) { = false; document.write("your total " + total); } } };
there difference between a = true
, a == true
.
your for-loop asking "can set 'a' true?", answer yes, , loop continues.
change condition a == true
(thus asking "is value of 'a' true?")
to elaborate, in programming languages, distinguish between assignment ("make 'x' 4") , testing equality ("is 'x' 4?"). convention (at least in languages derive syntax c), use '=' assign/set value, , '==' test.
if i'm understanding specification correctly (no guarantee), happens here condition condenses follows:
- is (a = true) true?
- complete bracket: set true
- is (a) true? (we set true, must be!)
Comments
Post a Comment