Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,34 @@ let Question = function (question, answer, correctAnswer) {
this.answer = answer;
this.correctAnswer = correctAnswer;
this.askQuestion = function () {
var randomNumber = Math.floor(Math.random() * 3)
randomNumber
questionsArray[randomNumber]
// questionsArray[randomNumber]
console.log(this.question)
console.table(this.answer)
}
this.checkAnswer = function (answer) {
if (answer == this.correctAnswer) {
this.checkAnswer = function () {
var questionnaire = prompt('Write your answer here')
if (questionnaire == this.correctAnswer) {
console.log('Correct Answer');
gameScore++;
console.log(gameScore)
start();

} else if (questionnaire == 'exit'){
alert('game aborted');
} else {
console.log('Incorrect Answer');
console.log('incorrect answer')
start();
}
}
};

let isGameRunning = true;
let questionNumber = 0;
// let isGameRunning = true;
// let questionNumber = 0;

var question1 = new Question("How many members are there in TWICE?", ["7", "8", "9"], 2);
var question2 = new Question("Who is the main dancer in TWICE?", ["Momo", "Dahyun", "Nayeon"], 0);
var question3 = new Question("What year did TWICE debut?", ["2014", "2015", "2016"], 1);
let questionsArray = [question1, question2, question3];
var answersArray = [["7", "8", "9"], ["Momo", "Dahyun", "Nayeon"], ["2014", "2015", "2016"]];
var gameScore = 0;


Expand All @@ -39,17 +43,23 @@ var gameScore = 0;



(function start() {
while (isGameRunning) {
const currentQuestion = questionsArray[questionNumber];
let tempAnswer = prompt(currentQuestion.askQuestion());
(start = () => {
// while (isGameRunning) {
var randomNumber = Math.floor(Math.random() * 3)

questionsArray[randomNumber].askQuestion();
questionsArray[randomNumber].checkAnswer();

currentQuestion.checkAnswer(tempAnswer);
console.log('%c Current Score:', 'color: blue; font-size: 14px', gameScore)
// let tempAnswer = prompt(currentQuestion.askQuestion());

if (tempAnswer == "exit"){
isGameRunning = false;
}
// currentQuestion.checkAnswer(tempAnswer);
// console.log('%c Current Score:', 'color: blue; font-size: 14px', gameScore)

// if (tempAnswer == "exit"){
// // isGameRunning = false;
// alert('Game Aborted!')
// }

}
// }
})();

47 changes: 0 additions & 47 deletions main1.js

This file was deleted.