Someone to help me please!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Someone to help me please!?

There are four buttons that have value 1, 2, 3 and 4. If I click on 1 I want a message that alert 1. When I click on 2 the message will alert 2 so on for each button. I do not want the code to be too long by doing 4 different functions for each event click. So I will use a single function alert (); for 4 click events What needs to be done: 1-) Do I have to pass a parameter to the function alert ()? How to do this with the events? 2-) Do I have to add other click events to modify a defined variable in order to select the alert message? 3-)Do I need class or objects? I want tips to be more effective. Thank you!

15th Oct 2019, 3:08 AM
Cedrick
Cedrick - avatar
5 Answers
+ 3
1. yes just pass the string, you can add an event by adding onclick attribute in your html element 2. not really, but its depend on how you implement it. 3. no
15th Oct 2019, 4:26 AM
Taste
Taste - avatar
15th Oct 2019, 9:39 AM
Gordon
Gordon - avatar
+ 2
Thank you Taste. How to to that (option1)?
15th Oct 2019, 5:24 AM
Cedrick
Cedrick - avatar
+ 2
Thank you Gordon
15th Oct 2019, 11:06 AM
Cedrick
Cedrick - avatar