20 AnswersNew Answer
I was trying to make a code like: 1. When the button is clicked for the 1st time, it will print 0. 2. When it's clicked 2nd time, it will print 1. 3. When it's clicked 3rd time, it will print 2. 4. When it's clicked for the 4th time, again the value will start from 0. 5. When it's clicked for the 5th time, it will print 1. 6. The 7th time, it will again start from 0. I think i've told my question clearly. Pls give the solution ❤❤❤ I've tried, here is the code: https://code.sololearn.com/WJtLpmv9dQUf/?ref=app
10/13/2019 2:42:19 PMRaihan Arefin🇧🇩 [Thunder_Rabbit⚡⚡]
20 AnswersNew Answer
Thanks a lot Russ for telling "You don't need a for loop, it's much easier" and Vignesh Rathnam for using "onload" event in ur code, these helped me a lot. Here is the solution to my question : https://code.sololearn.com/W75eMF2C8pZl/?ref=app
Russ my code is given :) Pls see again
Russ will i need to use x[i].onclick in a for loop?, as it have an "i" with it?
👑Mr_Gamer👑 what ain't?
Are u talking about my code 👑Mr_Gamer👑? Then pls see my solution code again, it returns. And if u are talking about Vignesh Rathnam 's code, well,,, he just told about the structure(so it doesn't need to return anything). Solving is my job.
Your first issue is that you're getting your button using getElementsByTagName which returns an array. This means you either have to do x.onclick = ... or add an id to the button and get it using getElemenyById. Also, I'd suggest adding an extra div or something to print your number to when you press the button. An extra hint: within your onclick() function, you don't need any for loops. It is much simplet than that.
No. You only have 1 button. getElementsByTagName("button") will return an array of all buttons on your page. As you only have 1 button, x will be your only button. I'd advise giving it an id and getting it using getElementById to make it all tidier. This is what I mean: https://code.sololearn.com/WRM6BwHK6iPy/?ref=app
Russ There's no sin in asking for code in relation with the question, what's with self down voting anyways? did you miss it at first look (been there) 😁
Ipang exactly that. The link to the code was right there, but I don't know what was going on in my brain.
Russ It happens I guess, but no need to punish yourself over that 😁
It's not as if it really matters though. It's only internet points 😊
You are right Russ 👍
You need to load DOM(which is another page) (document elements ) so they wont be null https://code.sololearn.com/WuMn5F4U8dn8/?ref=app
At least show us what you've already tried. Edit: downvoted myself because I'm an idiot.
🤦♂️ wow, it's one of those days! Sorry!
Welcome Raihan🇧🇩 [Thunder_Rabbit⚡⚡]
👀Nah It Ain't 💔
It Ain't Giving Out A Value👀💔
Learn Playing. Play Learning
SoloLearn Inc.4 Embarcadero Center, Suite 1455
Send us a message