I am trying to accomplish the following and I don't know why I am struggling. Create a new fiddle that contains a button with the text "x2" and the number 1 like this:
1 x2
Use Javascript to make it so that each time the button is clicked, the number above the x2 button will double. Send me the link to the fiddle.
Here is what I have thus far. I know I am targeting the button via JS but I cannot figure out how to return the updated value when the x2 button is clicked.
<p id="counter">1</p>
<button onclick="calc()">x2</button>
<script>
function calc() {
var element = document.getElementById("counter") *2;
return counter.innerHTML = element;
}
</script>