Documente Academic
Documente Profesional
Documente Cultură
/* ============================== */
// Class
class MCQ {
this.question = question;
this.options = option;
this.answer = answer;
this.category = category;
displayQuestion() {
result += this.question
result += "\n"
return result;
displayHelpPassQuestion() {
do {
} while (i == this.answer);
result += this.question
result += "\n"
if (i < this.answer) {
} else {
return result
displayQuestionOnly() {
result += this.question
return result;
displayOptionOnly(i) {
result += this.options[i]
return result;
}
validateAnswer() {
result += this.answer + 1
return result;
class Quiz {
constructor() {
this.quizQuestions = [];
this.quizQuestions.push(new MCQ("Which is the LONGEST river in the world?", ["Amazon River", "Nile", "Huang He", "Yangtze"], 1, 1));
this.quizQuestions.push(new MCQ("Which is the SECOND largest country in terms of land area?", ["United State", "China", "Canada", "Russia"], 2, 1));
this.quizQuestions.push(new MCQ("Who is the first person to walk on the moon?", ["Buzz Aldrin", "Pete Conrad", "Alan Bean", "Neil Armstrong"], 3,
1));
this.quizQuestions.push(new MCQ("Which is the smallest ocean in the world?", ["Pacific Ocean", "Atlantic Ocean", "Arctic Ocean", "Indian Ocean"], 2,
1));
this.quizQuestions.push(new MCQ("Who is the first president of the United State?", ["George Washington", "Abraham Lincoln", "Barack Obama",
"Donald Trump"], 0, 1));
this.quizQuestions.push(new MCQ("Hyper Text Markup Language Stand For?", ["JavaScript", "XHTML", "CSS", "HTML"], 3, 2));
this.quizQuestions.push(new MCQ("Which language is used for styling web pages?", ["HTML", "JQuery", "CSS", "XML"], 2, 2));
this.quizQuestions.push(new MCQ("Which is not a JavaScript Framework?", ["Python Script", "JQuery", "Django", "NodeJS"], 2, 2));
this.quizQuestions.push(new MCQ("Which is used for Connect To Database?", ["PHP", "HTML", "JS", "All"], 0, 2));
this.quizQuestions.push(new MCQ("What is the name given to a network of servers that deliver information and is entirely on the internet and is
accessed through web browsers", ["World Wide Web", "Cloud", "Internet", "Network"], 1, 2));
this.quizQuestions.push(new MCQ("Which 2019 hit contains the lyrics 'I got the horses in the back / Horse tack is attached / Hat is matte black / Got
the boots that's black to match'?", ["Old Town Road by Lil Nas X", "Dark Horse by Katy Perry", "Black Horse and the Cherry Tree by KT Tunstall", "Just Like
Them Horses by Reba McEntire"], 0, 3));
this.quizQuestions.push(new MCQ("Ed Sheeran teamed up with which American superstar on the May hit 'I Don't Care'?", ["Arianna Grande", "Selena
Gomez", "Justin Bieber", "Calvin Harris"], 2, 3));
this.quizQuestions.push(new MCQ("Sophie Turner appeared in the video of which Jonas Brothers single?", ["Sucker", "Pom Poms", "Cool", "Old Town
Road"], 0, 3));
this.quizQuestions.push(new MCQ("Calvin Harris teamed up with which English singer for to top the charts with the single 'Promises'?", ["Sam Smith",
"Drake", "Dua Lipa", "Cardi B"], 0, 3));
this.quizQuestions.push(new MCQ("The soundtrack to which Hugh Jackman and Zac Efron film spent weeks at the top of the British Album charts in
early 2018?", ["A Star Is Born", "Spider-Man: Into the Spider-Verse", "Black Panther", "The Greatest Showman: Reimagined"], 3, 3));
this.quizQuestions.push(new MCQ("Which striker scored the first hat-trick of the 2018/19 Premier League season against Huddersfield Town?",
["Mohamed Salah", "Sergio Agüero", "Harry Kane", "Raheem Sterling"], 1, 4));
this.quizQuestions.push(new MCQ("Maurizio Sarri replaced which fellow countryman in charge at Chelsea?", ["Antonio Conte", "Unai Emery", "Pep
Guardiola", "Javi Gracia"], 0, 4));
this.quizQuestions.push(new MCQ("From which sport does the term 'down to the wire' originate?", ["Darts", "Horse Racing", "Ice Hockey", "Football"],
1, 4));
this.quizQuestions.push(new MCQ("How many players are there on a Baseball team?", ["9", "5", "11", "7"], 0, 4));
this.quizQuestions.push(new MCQ("Which country is the winner of the Fifa World Cup 2018", ["Germany", "Brazil", "England", "France"], 3, 4));
getNumberOfQuestions() {
return this.quizQuestions.length;
getQuestionAt(index) {
return this.quizQuestions[index];
/* ============================== */
// Function
function selection() {
userSelection = readline.question(">> ");
return userSelection;
function userInputAnswer() {
return choice;
function buildQuiz() {
switch (userSelectionList[0]) {
displayQuestionList.push(myQuiz.getQuestionAt(i));
};
break;
displayQuestionList.push(myQuiz.getQuestionAt(i));
};
break;
displayQuestionList.push(myQuiz.getQuestionAt(i));
};
break;
displayQuestionList.push(myQuiz.getQuestionAt(i));
};
break;
displayQuestionList.push(myQuiz.getQuestionAt(i));
};
function getNumberOfDisplayQuestions() {
return displayQuestionList.length;
}
function getDisplayQuestionAt(index) {
return displayQuestionList[index];
function displayQuiz() {
var index = 0;
do {
var q = getDisplayQuestionAt(index);
result += "-----------------------------\n"
result += "-----------------------------\n"
result += q.displayQuestion();
result += "-----------------------------"
console.log(result);
userInputAnswer();
do {
if (choice != "1" && choice != "2" && choice != "3" && choice != "4") {
if (choice == "") {
console.log("ALERT! You leave the question blank.\nWould you like to complete the question before process to next question.")
console.log("-----------------------------");
selection();
do {
if (userSelection != "Y" && userSelection != "y" && userSelection != "N" && userSelection != "n") {
selection();
} // validator
// Help the user when the user face problem in answering current question
if (helpPass == 1 || helpPass == 2) {
selection();
do {
if (userSelection != "Y" && userSelection != "y" && userSelection != "N" && userSelection != "n") {
selection();
} // validator
helpPass--;
var q = getDisplayQuestionAt(index);
result += "-----------------------------\n"
result += "-----------------------------\n"
result += q.displayHelpPassQuestion();
result += "-----------------------------"
console.log(result);
do {
userInputAnswer();
if (choice != "1" && choice != "2" && choice != "3" && choice != "4") {
console.log("ERROR! You must answer the question when you using Help Pass.")
} // validator
} while (choice != "1" && choice != "2" && choice != "3" && choice != "4")
console.log("-----------------------------");
userInputAnswer();
} while (userSelection != "Y" && userSelection != "y" && userSelection != "N" && userSelection != "n")
} else {
console.log("Sorry, the remaining Help Pass already being used just now. You unable to get any more help.");
console.log("-----------------------------");
userInputAnswer();
} while (userSelection != "Y" && userSelection != "y" && userSelection != "N" && userSelection != "n")
console.log("ERROR! You can only choose the choices above.\nPlease select the choices provided:");
userInputAnswer();
} // validator
} while (choice != "1" && choice != "2" && choice != "3" && choice != "4" && choice != "");
userAnswerList[index] = choice;
console.log("-----------------------------");
selection();
do {
if (userSelection != "N" && userSelection != "n" && userSelection != "P" && userSelection != "p" && userSelection != "X" && userSelection != "x") {
console.log("-----------------------------");
selection();
} // validator
if (index != getNumberOfDisplayQuestions() - 1) {
index++;
unattemptCheck();
console.log("-----------------------------\n");
do {
selection()
if (index != 0) {
index--;
} while (userSelection != "N" && userSelection != "n" && userSelection != "P" && userSelection != "p" && userSelection != "X" && userSelection != "x")
console.log("You haven't finished the quiz\nWould you like to continue or quit the quiz");
selection();
do {
if (userSelection != "C" && userSelection != "c" && userSelection != "Q" && userSelection != "q") {
selection();
} // validator
else
displayQuiz();
showResult();
} while (userSelection != "C" && userSelection != "c" && userSelection != "Q" && userSelection != "q")
console.log("-----------------------------\n");
showSelectedAnswers();
}
function unattemptCheck() {
var unattemptQuestion = 0;
if (userAnswerList[index] == "") {
unattemptQuestion++;
console.log("You have " + unattemptQuestion + " question/questions unattempted\nPlease answer the question/questions below.");
if (userAnswerList[index] == "") {
var q = getDisplayQuestionAt(index);
result += "-----------------------------\n"
result += "Question " + (index + 1) + " of " + getNumberOfDisplayQuestions() + "\n"
result += "-----------------------------\n"
result += q.displayQuestion();
result += "-----------------------------"
console.log(result);
userInputAnswer();
do {
if (choice != "1" && choice != "2" && choice != "3" && choice != "4") {
console.log("ERROR! You must answer the question before you want to submit and get your result.")
userInputAnswer();
} // validator
} while (choice != "1" && choice != "2" && choice != "3" && choice != "4")
userAnswerList[index] = choice;
do {
result += "\n"
result += "\n"
result += "\n"
console.log(result);
do {
if(userSelection != "0" && userSelection != "1" && userSelection != "2" && userSelection != "3" && userSelection != "4" && userSelection != "5") {
console.log("ERROR!")
console.log("Press 0 to submit your answers / Press [1 to 5] to select the question you would like to change your answer.");
selection();
} while (userSelection != "0" && userSelection != "1" && userSelection != "2" && userSelection != "3" && userSelection != "4" && userSelection != "5")
console.log(""); //Leave a space line
if (userSelection != 0) {
switch (userSelection) {
break;
break;
break;
break;
showResult();
}
// Function for showing the result
function showResult() {
var score = 0;
if (userAnswerList[i] == (getDisplayQuestionAt(i).validateAnswer())) {
score++;
result += "\n"
result += "-----------------------------\n"
result += "\n"
console.log(result);
switch (score) {
case 0: console.log("Looks like you must work harder. Try again next time. ^_^\n");
break;
case 1: console.log("Looks like you must work harder. Try again next time. ^_^\n");
break;
case 2: console.log("Looks like you must work harder. Try again next time. ^_^\n");
break;
case 3: console.log("Well done. You almost get full mark. Try again next time. ^_^\n");
break;
case 4: console.log("Well done. You almost get full mark. Try again next time. ^_^\n");
break;
/* ============================== */
// Array
/* ============================== */
// Variable
var helpPass = 2;
/* ============================== */
/*
===============================================================================================================================
======================= */
// Open
console.log("-----------------------------");
console.log("-----------------------------");
// Enter User details
do {
// Welcome
console.log("Hi " + name + ", please choose the quiz category you would like to attempt:");
console.log("-----------------------------");
// Category Selection
selection();
console.log("-----------------------------");
console.log("ERROR! You can only choose the options above.\nPlease select the options provided:");
selection();
console.log("-----------------------------");
} console.log(category[userSelection - 1] + " category selected.\n!!!Instructions!!!\nThis quiz consists of 5 multiple choice questions, and you are to
answer ALL the questions.\nEach question carrys ONE mark.\nIn the quiz, you can press N to proceed to the next question and P to the previous
question.\nGood Luck.\n");
userSelectionList[0] = userSelection;
selection();
console.log("-----------------------------");
selection();
buildQuiz();
displayQuiz();