0

Not updating the High Score :(

i am making a game in javascript. it has a score and high score element: <span id="scoreLabel">Score:</span> <span id="score">0</span> <span id="hscoreLabel">High Score:</span> <span id="highScore">0</span> and if the game ends it is supposed to update the highscore, assuming that the score is greater than the previous high score: if(END){ sc = document.getElementById("score").innerHTML; hsc = document.getElementById("highScore").innerHTML; sc>hsc?document.getElementById("highScore").innerHTML = sc: document.getElementById("highScore").innerHTML = hsc; document.getElementById("score").innerHTML = 0; END = false; setup(); } the first time that it runs, when the high score is 0, it will update, but for some reason it wont ever do it after....... if anyone can help :D

1st Mar 2017, 3:35 AM
Michael Szczepanski
Michael Szczepanski - avatar
4 ответов
+ 4
What you get from 'innerHTML' property is a string value: you may convert it to number to be able to properly compare the values ;) For making you code working here in playground, you just have to link the library you need normally, with <script> tags in <head>. If you want use the JS tab, you must know that's silently linked to Html tab ( so the Css tab ) as if was in <head>... For that reason, this code is exeuted before dom is loaded, so, for access to it, you need to wait for 'window.onload' event ( for example ). Anyway, appart from these few adaptations, and some limitations of code playground, your codes should be mostly able to work here :P
1st Mar 2017, 6:26 PM
visph
visph - avatar
0
the first time it will update it, after that it doesnt. it is supposed to work but doesnt.... it keeps it as the previous high score.... :( WHY ME
1st Mar 2017, 4:25 AM
Michael Szczepanski
Michael Szczepanski - avatar
0
post it on here? lol its Not close to done.... i can post it when i finish the logic. and in order for this to work on CP i would have to import the p5.js files, how would i do that. also the create canvas... i tried that eariler and it didnt work :/
1st Mar 2017, 4:31 AM
Michael Szczepanski
Michael Szczepanski - avatar
0
"NO CODES" it says.... :D
1st Mar 2017, 4:50 AM
Michael Szczepanski
Michael Szczepanski - avatar