javascript - if statements within while loop -


i have looked @ sites www.w3schools.com, www.developer.mozilla.org, www.codeacademy.com, , www.tutorialspoint.com , have still had hard time looking example of wrong code. first off, here code:

var randomnumber = math.floor(math.random()); while(randomnumber > .5) { var name = prompt("do want play game? checkers or something?"); if (name === "yes") {     console.log("good jorb!"); } else if(name === "yes") {     console.log("good jorb!"); } else if(name === "yes.") {     console.log("good jorb!"); } else if(name === "yes.") {     console.log("good jorb!"); } else if(name === "yup") {     console.log("good jorb!"); } else if(name === "yup.") {     console.log("good jorb!"); } else if(name === "yup.") {     console.log("good jorb!"); } else if(name === "yup") {     console.log("good jorb!"); }  } else if(name === "no.") {     console.log("go away!!!!!"); } else if(name === "no") {     console.log("go away!!!!!"); } else if(name === "no") {     console.log("go away!!!!!"); } else if(name === "no.") {     console.log("go away!!!!!"); } else if(name === "nope") {     console.log("go away!!!!!"); } else if(name === "nope.") {     console.log("go away!!!!!"); } else if(name === "nope") {     console.log("go away!!!!"); } else if(name === "nope.") {     console.log("go away!!!!!"); }  else {     console.log("i don't know, man. don't know"); } var randomnumber = math.floor(math.random()); } 

my question how prompt loop if meets right requirements (set while loop). feel have placed prompt within while loop in way doesn't make sense or loop may make more sense while loops, have read, used when want event keep looping until specific condition met (as opposed in loops when event keeps looping until variable count reaches point). while appreciate offering making loop function more efficient (i aware have alot of else if conditions sure consolidated array or something) not necessary. help.

your variable randomnumber initialized first line, change it's value use randomnumber = newvalue newvalue value wish set to, using method or hardcoded value. not need use var keyword again.

also using math.floor method on math.random return 0, math.random return number between 0 , 1, floor 0.

you missing closing bracket on while loop.

i cleaned code little chain if boolean operators, although there better ways construct code.

var randomnumber = math(math.random()); while(randomnumber > .5) {     var name = prompt("do want play game? checkers or something?");     if (name === "yes" || name === "yes" || name === "yes." || name === "yes." || name === "yup" || name === "yup." || name ===  "yup." || name === "yup")     {         console.log("good jorb!");     }      else if(name === "no." || name === "no" || name === "no" || name === "no." || name === "nope" || name === "nope." || name ===  "nope" || name === "nope.")     {         console.log("that's bad.");     }     else      {         console.log("i don't know, man. don't know");     }     randomnumber = math(math.random()); };// close while loop. 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -