So I have this HTML Code
var number = document.getElementById("number");
function ClickFunction() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value ;
document.getElementById('number').value = value;
}
function Grandma() {
number.value = number.value - 10;
}
<input type="text" id="number" value="0" />
<input type="button" onclick="ClickFunction()" value="Klick mich!" >
<p align="right">
<input type="button" onclick="Grandma()" value="Kosten: 10 Cookies -> Die Großmutter (macht ein klick mehr)" >
</p>
As you can maybe see i am working on a cookie clicker game. I want to make a Grandma that removes 10 from the current amount of cookies and so makes the user per click 2 cookies instead of one. I am fairly new tho. Any help is greatly apreciated
Small Edit: I dont know why but somehow the code works here on stack overflow but not on my local Website
CodePudding user response:
If you want to increase the cookie value every time grandma get 10 then:
var number = document.getElementById("number");
var incremental = 1
function ClickFunction() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value = value incremental;
document.getElementById('number').value = value;
}
function Grandma() {
number.value = number.value - 10;
incremental
}
CodePudding user response:
you can use Replace function. As your input is a string.