Skip to content
Advertisement

Changing HTML text based on a value entered into an input box

I am creating a website and would like to make a tool using JavaScript to choose someone’s skateboard size depending on their shoe size. This is the code I am using:

JavaScript
JavaScript

No matter what I type into the text box there is always a “?” that shows up on my website. What can I do/ change to fix this. What I want to happen is if someone types for example “10” into the text box, “8.25” should be printed. I would also appreciate any other tips to improve my code.

Advertisement

Answer

Try this:

JavaScript
JavaScript
What I have changed:
  • Added an event listener. You checked the input value instantly when the page is loading. Therefore it always was empty.
  • Changed the switch statement. You can read more about that here: Switch on ranges of integers in JavaScript
  • Added a p tag to display result. This is better than writeDocument().
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement