So right now I’m trying to program what would essentially be a simple game where the user is given a riddle and when they give the correct answer they are allowed to move on to the next riddle.
Right now i can bring up a prompt that you then answer the question for which leads to more text, and i can hypothetically add a button in … but then along with the button comes all of the coding surrounding it also?
Is there anyway to fix this? Or is there a better coding alternative for what i’m trying to do? I kind of wish I knew how to use forms instead of prompts and buttons but from what i’ve tried to find i can’t seem to see any way of doing that.
Here’s what i’ve written so far (sorry i haven’t posted on this website before, i’m actually just pretty desperate now) (Ps. Im aware that i’m very bad at coding):
<p>Click the button!.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function nextButton()
{{
<button onclick="nextButton()">Next question!</button>
}
var y;
var name=prompt("What are bunnies?");
if (name!="fluffy")
{
y= name + " " + "is" + " " + "wrong!";
document.getElementById("demo").innerHTML=y;
}
else
{
y="correct!";
document.getElementById("demo").innerHTML=y;
}
}
function myFunction()
{
var x;
var name=prompt("what is cute a fluffy and adorable?");
if (name!="a bunny")
{
x= name + " " + "is" + " " + "wrong!";
document.getElementById("demo").innerHTML=x;
}
else
{
x="correct!" + nextButton ;
document.getElementById("demo").innerHTML=x;
}
}
Maybe change your nextButton function to the following:
and see if that works.
EDIT: Also change
To:
That should fix the script problem.
Good luck!