Advertisement
Qrist

Game (Question_Answer)

Nov 9th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let points = 0;
  2. let wantsToExit = false;
  3.  
  4. while (wantsToExit === false) {
  5.  
  6.   let question = prompt("Player 1: Enter a question. Type 'exit' to end the game");
  7.  
  8.   if(question ==="exit"){
  9.   alert("Game over");
  10.   wantsToExit=true;  
  11.   }
  12.   else if(question !=="exit"){
  13.    let right_answer = prompt("Player 2: " + question + " Type 'exit' to end the game");
  14.    if(right_answer === "exit"){
  15.      alert("Game over");
  16.    wantsToExit=true
  17.    }
  18.    else if(right_answer !=="exit"){
  19.    let answer = prompt("Player 2: " + question + " Type 'exit' to end the game");
  20.    if(answer==="exit"){
  21.      alert("Game over");
  22.    wantsToExit=true;  
  23.    }
  24.    else  if (answer === right_answer) {
  25.         alert("Woo hoo, you've got a point");
  26.         points = points + 1;
  27.     } else {
  28.         alert("Wrong answer, try again");
  29.     }
  30.    
  31.   }
  32. }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement