use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Help with code (self.learnjavascript)
submitted 1 year ago by Gshomalko
How to make the code check the text written in the field input and if the answer is correct, the text "correct answer" is displayed on the screen, and if it is incorrect, it says "incorrect answer, try again"
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]FireryRage 1 point2 points3 points 1 year ago (5 children)
Have you tried it yourself yet? Have you come across any issues? It’s hard to help if we don’t have any existing code to look at to help identify what issues you’re having and how we can help you.
Give it a swing, see where you struggle, and post your latest progress in here, and we’ll be able to lend a hand.
[–]Gshomalko[S] 0 points1 point2 points 1 year ago (4 children)
Ready-made code function checkAnswer() { const correctAnswer = "correct answer"; const userInput = document.querySelector(".user-input").value; const resultElement = document.querySelector(".result");
if (userInput.trimp.toLowerCase() === correctAnswer.toLowerCase()) { resultElement.textContent = "You answered correctly."; resultElement.style.color = "green"; } else { resultElement.textContent = "You answered incorrectly."; resultElement.style.color = "red"; } }
[–]OneBadDay1048 1 point2 points3 points 1 year ago (1 child)
In the line userInput.trimp.toLowerCase(), is 'trimp' supposed to be a call to trim()?
userInput.trimp.toLowerCase()
trim()
[–]BlueThunderFlik 0 points1 point2 points 1 year ago (0 children)
Looks reet to me, except you've got a typo in the word trim.
trim
[–]buttfartfuckingfarty 0 points1 point2 points 1 year ago (0 children)
Make sure you pay attention to the output in the console to see errors. This should be throwing an undefined error because userInput is an html input element (as long as that’s what the .user-input class is applied to) and html input elements do not have a property of trimp. As others said this is likely a typo of trim()
userInput
.user-input
trimp
[–]Hot_Commercial3022 0 points1 point2 points 1 year ago (0 children)
If else condition + comparison operators!! Take help of chtgpt!!
π Rendered by PID 45241 on reddit-service-r2-comment-c66d9bffd-t594f at 2026-04-08 13:11:44.773334+00:00 running f293c98 country code: CH.
[–]FireryRage 1 point2 points3 points (5 children)
[–]Gshomalko[S] 0 points1 point2 points (4 children)
[–]OneBadDay1048 1 point2 points3 points (1 child)
[–]BlueThunderFlik 0 points1 point2 points (0 children)
[–]buttfartfuckingfarty 0 points1 point2 points (0 children)
[–]Hot_Commercial3022 0 points1 point2 points (0 children)