+ 3
I need help
Does anybody know how to create an answer box for a translation I have in my code? https://code.sololearn.com/W3Uc199ZU6M9/?ref=app
4 Answers
+ 3
Sorry I forgot the .value part, because you want the value and not the object ... :) copy this:
<!-- Answer Section -->
<div class="answerSection">
<script>
function answerCheck() {
var uin = document.getElementById("userAnswer").value;
var rightans = "I love learning code"
if(uin == rightans) {
document.getElementById("ansPara").innerHTML = "Right answer";
}
else {
document.getElementById("ansPara").innerHTML = "False answer"
}
}
</script>
<br />
<br />
<input type="text" name="UsersAnswer" placeholder="Your translation" id="userAnswer" />
<input type="submit" value="translate" onclick="answerCheck()" />
<br />
<p id="ansPara">
Your answer...
</p>
<div>
+ 3
I added it, but when I go to put the answer in it comes back false.
+ 2
Add this to your html code:
<script>
function answerCheck() {
var uin = document.getElementById("userAnswer");
// I dont know if you have a macro for I love learning code, so I made it like this ...
if(uin == "I love learning code") {
alert("right answer!");
}
else {
alert("false answer!")
}
}
</script>
<br /> <br /> <input type="text" name="UsersAnswer" value="Your translation" id="userAnswer" />
<input type="submit" value="Submit" onclick="answerCheck()">
+ 1
Thank you so much! I've been trying to figure this out for days!!