lundi 5 juin 2017

Javascript while loop terminating without executing the statement

I want my program should work like: it should ask user for the answer over and over until correct answer and at the end alert with well done message.

Any help why it isn't woking that way????

var answer = prompt('What is the capital of Pakistan?');
while(answer != 'islamabad'){
  if(answer === 'islamabad'){
    alert('Your answer is correct!');
  }else if(answer != 'islamabad'){
    answer = prompt('Try again.');
  }else{
    alert('Well Done');
  }
}

Aucun commentaire:

Enregistrer un commentaire