So I am in beginning stages of making my portfolio on here, and a feature I’ve added is one that when someone clicks a button, the title changes to another language. I’ve successfully gotten that to happen, however, I want to make it loop. Below is my code, can you help me do so?
Thank you very much for any help!
Maybe with setInterval(function, number).
Opps. Swoodend is right, put them in an array and then you can do the math so it loops (I remember there was a very nice way to do that with the % operator).
My first post had nothing to do with the question xD but after getting that loop function right you can use that interval function so it changes automatically.
Would it be possible for you to maybe show me? I don’t understand
I think I misunderstood what OP was asking for so I withdrew my post
Basically I want to make the title change to different languages with the button, but the languages stop, I want it to cycle through the languages and never stop.
OK. So every time the user clicks the button they see a different language. To do this you don’t really need to loop at all.
One option is to store all the phrases you want to display (in each language) in an array. When the user clicks a the button a random number is chosen. That random number is used to select a phrase from the array and it is displayed on your page.
If you find yourself stuck with this I would recommend going over the course material again to really solidify your understanding of loops, syntax, etc.
Your answer was right, I was the one that read something else xD
Instead of doing h3 .text( something ) for each item you can create an array and put everything in there: var array = [‘first’,‘second’,‘third’,‘another one’];
Then you can use for loops and the array’s index to create those h3 elements. Then the math thing so you can reset the index to 0 once it reaches its length and set that up with the click event of the button.