'I'm trying to make a test html where pressing a button moves along the index of an array which starts at 0
When I test this code it only shows 0, despite the button function running. What have I done wrong? Since I'm only starting out with JavaScript I'd appreciate an in-depth answer.
var y = 1;
myFunction();
function myFunc() {
var z = 1
var x = y + z;
y = x
alert("f");
}
function myFunction() {
y = 0;
alert("sdrz");
}
const numbers = ["0", "1", "2", "3"];
document.getElementById("demo").innerHTML = numbers[y];
<p id="demo"></p>
<button onclick="myFunc()">+1</button>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
