+ 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

28th Jan 2018, 12:26 AM
Cody Greathouse
Cody Greathouse - avatar
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>
28th Jan 2018, 5:16 PM
avatarluca
avatarluca - avatar
+ 3
I added it, but when I go to put the answer in it comes back false.
28th Jan 2018, 3:27 PM
Cody Greathouse
Cody Greathouse - avatar
+ 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()">
28th Jan 2018, 2:55 PM
avatarluca
avatarluca - avatar
+ 1
Thank you so much! I've been trying to figure this out for days!!
28th Jan 2018, 6:22 PM
Cody Greathouse
Cody Greathouse - avatar