javascript - Why no fizzbuzz being printed out? -


this code. not getting fizz buzz printed. getting numbers. explain why? thanks

printout = "";   (var x=1; x < 101 ; x++) {     switch(x) {        case((x%3) == 0):       printout+="\n"+ "fizz" ;       break;        case((x%5) == 0):       printout+="\nbuzz";       break;        default:       printout+="\n" + x ;       break;    }  } console.log(printout); 

you're using switch statement improperly. each case (value): supposed run whenever x equals value.

to solve problem, remove switch statement entirely, , substitute ifs each case:

for (var x = 1; x < 101; x++) {     if ((x % 3) == 0)         printout += "\n" + "fizz";     else if ((x % 5) == 0)         printout += "\nbuzz";     else         printout += "\n" + x; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -