+ 1
Can you help out in this code work
dictionary index value I'm trying to get the code to say, if next button, ask next question index.value num1 = ["What is 3 x 6": "18", "What is 3 x 7": "21", "What is 3 x 8": "24"] var i = 0; function myFunc() { for(i =< 0) = num1.length; i++; if(sanserif.value == num1[i++]) { document.getElementById("monospace").innerHTML = "correcct"; } } function nextFunc() { document.getElementById("monospace").innerHTML = num1[i++] } https://code.sololearn.com/WT6RNLRf51xp/?ref=app
20 Respuestas
+ 2
//Sorry, I had to modify a lot your code so that it would work like what you like and I improved it little :
const num1 = {"What is 3 x 6": "18", "What is 3 x 7": "21", "What is 3 x 8": "24"};
let i = -1;
function myFunc()
{
if(document.getElementById("sanserif").value == Object.values(num1)[i])
{
document.getElementById("monospace").innerHTML = "correct";
}
}
function nextFunc()
{
if(i < Object.keys(num1).length - 1 && document.getElementById("monospace").innerHTML == "correct" || !document.getElementById("monospace").innerHTML) document.getElementById("monospace").innerHTML = Object.keys(num1)[++i]
}
nextFunc();
//If you need explanations, I am here, or you can follow me so that I will be able to help you in your codes or learn you with my tutorials which are coming soon
+ 3
The code has to ask
What is 3 x 6
18
Next( )
What is 3 x 7
21
Next( )
+ 1
Please explain a little more what you want to do
+ 1
Yes, and also your code will be faster if you access monospace, sanserif, cursive and the others by a variable (const monospace = document.getElementById("monospace"); //good) instead by document.getElementById() because JS will navigate only 1 time through the DOM to find them instead of more
0
Wow it works, you really nailed it on this one
Thanks a lot
0
Thanks VCoder the [Math.floor(Math.random() * tryAgain.length)] works just fine,
sorry I trying to reply but the messages are not sending on my phone. But anyways everything is fine now
0
Replace the else if statement by an else one
0
And you don't need to write +1, just 1
0
Ok do you mean like this?
else
{
document.getElementById("monospace").innerHTML = tryAgain[Math.floor(Math.random()*tryAgain.length];
}
0
Ok cool
But how do I hide the next() function thou until a correct answer is clicked
0
You speak about the last line ?
0
Yes
0
Try to comment it and you will understand why I add it
0
Ok I'll try now
0
It doing nothing
0
if(correct answer then next);
is this a possible code
0
Did you notice that the first question isn't displayed
0
Yes
0
1_close the parentheses of Math.floor()
2_don't worry, the last line is used only to display the first question
0
Ok thanks