if statement - javascript prompt failing after one try -


i creating simple bootstrap page when first open page page asks prefer dark theme or light theme (the theme changes based on answer.) additionally want have if user types other dark or light prompt keeps asking until chose or b. unfortunately, happens prompt asks user , type else in , asks again, if type else 2 answers gives , resorts default background. there way prevent this? here code....

var background_image = prompt("do prefer light background or dark background?")   if (background_image == 'light') {   $('body').css('background-image', 'url("assets/background.jpg")') } else if (background_image == 'dark'){   $('body').css('background-image', 'url("assets/dark.jpg")') } else {   var background_image = prompt("do prefer light background or         dark background?") }      body{  background-image: url("../assets/grey.jpg"); } 

also, if type or b first time try correct typing in light or dark on 2nd try automatically reverts default theme

thank you

well, code ends after second prompt, why expect run 1 more time.

you need make - try making function, , rerun function instead of 2nd prompt. learn recursion.

see this:

function ask() {    var background_image = prompt("do prefer light background or dark background?");      if (background_image == 'light') {      $('body').css('background-image', 'url("assets/background.jpg")')    } else if (background_image == 'dark') {      $('body').css('background-image', 'url("assets/dark.jpg")')    } else {      ask();    }  }    ask();

also, if type or b first time try correct typing in light or dark on 2nd try automatically reverts default theme

again, 2nd try in code irrelevant nothing happens after it.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -