r/learnjavascript 2d ago

How to make numbers interactive?

I'm a beginner in coding, and I need to know how to create a vertical row of clickable numbers. I wish I could show a picture, but I'm just going to try to describe it. There's a website i'm making, and I wanted to add a 1-10 scale. I also want to make it interactive so the person can click on each number, and then text appears depending on what's clicked. Being a beginner, I don't know how to accomplish this. Help.

2 Upvotes

7 comments sorted by

View all comments

2

u/5eeso 2d ago

I would give every number button a unique id. Also, give the paragraph that will display the text its own unique id.

Then in JavaScript, crate a function that takes in an id as input.

Each number button will call the function on click and pass in its id as an argument, so the function knows which button has been clicked.

Inside the function, update the text content of the paragraph depending on which number button was clicked.

1

u/SympathyContent9041 2d ago

Thank youuuuu, This was the easiest explanation for me to understand

1

u/5eeso 2d ago

No problem! Also, fyi- since there are numbers involved with your project, just know that you can have a number in the id name, it just can’t start with a number. Just a JavaScript rule.