Question
Java script)) how to make random questions and round? Hello, I should make random questions game without html (It means I should use only Javascript)
Java script)) how to make random questions and round?
Hello, I should make random questions game without html (It means I should use only Javascript)
I wrote some scripts for game
Here :
var Playerfirstname = prompt("Enter your first name");
var Playerlastname = prompt("Enter your last name");
alert(`Hello ${Playerfirstname} ${Playerlastname}!`);
console.log("Player name is :",Playerfirstname +","+ Playerlastname);
var round1quiz = [
['Whats is 2 + 2', '4'],
['What is 3 * 3', '9'],
['What is 5 * 5', '25']
];
var round2quiz = [
['Whats my name', 'Ian'],
['Where am i from', 'India'],
['My favorite Food', 'Idly']
];
var round3quiz = [
['Whats my name', 'Ian'],
['Where am i from', 'India'],
['My favorite Food', 'Idly']
];
score = 0;
var questions = 0;
function round1()
{
shuffle(round1quiz)
var round1 = prompt("If you want to start Quiz game, enter 'yes'");
if (round1 == 'yes' || round1 == 'y')
{
alert("Let's start Quiz game!");
alert("Round 1");
questions = round1quiz;
}
else
{
alert("sorry, try again");
var round1 = prompt("If you want to start Quiz game, enter 'yes' or 'y' ");
}
}
round1();
function round2()
{
}
function randomQuestions() {
return [rq(), rq(), rq()]
}
function rq() {
var a = getRandomInt(0, 100),
b = getRandomInt(0, 100),
operator = "+-*" [getRandomInt(0, 3)],
answer = operator === "+" ? a + b : operator === "-" ? a - b : operator === "*" ? a * b:0;
return ["what is " + a + operator + b, answer]
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function askQ(ans) {
var answer = prompt(ans[0], '');
if (answer == ans[1]) {
score++;
alert('Your are right!, you get money');
} else {
alert('Sorry, It is wrong answer');
}
}
// the loop that will ask all the questionseasy
function startquiz() {
for (var i = 0; i < questions.length; i++) {
askQ(questions[i]);
}
}
startquiz();
alert(score);
function shuffle(array) { //
var currentIndex = array.length,
temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
I wanna make round2 and round3. if player write all correct answer and choose playing round2, round2questions will display.
how can I make that code?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started