Menu

1 / 8

how to set my var back to 0 after a function? : r/learnjavascript

Reading 0:00
15s threshold

r/learnjavascript

5h ago

u/RefuseCommercial8024

how to set my var back to 0 after a function?

--fixed, just hadta remone the "let" at the end : -) --

hii i'm working on a page that lets u cycle through texts by clicking on an arrow but i've got some trouble actually making my js... cycle through.

let fruit = 0;

function next() { fruit ++; console.log(fruit)

if (fruit == 0) { document.getElementById("txt").innerHTML="bananas are fruits that look weird nd stuff";}

else if (fruit == 1) { document.getElementById("txt").innerHTML="coconuts are cool too i guessssss"; }

else if (fruit == 2) { document.getElementById("txt").innerHTML="and apples exist also!!!!"; }

else if (fruit > 2) { let fruit = 0;

}

}

i need to set my fruit var back to 0 if it's over 2 but i can't find a way to make it work...i'm pretty new to js too so my code probably isnt optimal lol

Roblox

•

Ad

The best shooter games are played with friends.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.