Nemôžem získať premennú zdravie aktualizované .. Dostanem aktualizáciu, ak som console.log to vo vnútri funkcie, ale to nebude mať vonku?
var health;
health = 9;
function scaringCat(event) {
var catAngry = new Audio("sounds/cat_hiss.mp3");
catAngry.play();
health = health -1;
return health;
}
buttons[1].addEventListener("click", scaringCat);
odpovede:
0 pre odpoveď č. 1Pozrite sa na tento jednoduchý kód javascript jeho aktualizácie premennej zdravie zakaždým. Kontrola konzoly.
<body>
<input type="button" value="Submit1" onclick="scaringCat()"></input>
<input type="button" value="Submit2" onclick="scaringCat1()"></input>
<script type="text/javascript">
var health;
health = 9;
function scaringCat() {
health = health -1;
console.log(health);
alert("click on submit2 now!!!")
}
function scaringCat1() {
var v=health;
console.log(v);
}
</script>
</body>