Wednesday, March 16, 2011

Ex 2.6 while it lasts...

What I learned on this Ex, a var MUST be initialized, else the script won't run.
{} are very important when there are more than one statement, if sometimes is not too clear on it..
And, the condition variable must exist before the condition, or you will get a no run.
still not too hard, just need to pay attention to the keyboard.

var ans ="";
while (ans != "4") {
ans = prompt("2 + 2 = ?", "4");
if (ans == "4") {
alert("Ok");
breack; }
else alert("NO!, again...");}

continuer reading after this ex, and you can see that var=4 is the same as var="4", for comparisons.

No comments:

Post a Comment