I have function of "endgame" and here's how the function goes
function endgame() {
setScreen("scorescreen");
ismytimergoing = false;
appendItem(scorelist, score);
for (var i = 0; i < scorelist.length; i++) {
if (scorelist[i] > scorelist[i +1]) {
highestnumber = scorelist[i];
} else if ((scorelist[i] == scorelist[i + 1])) {
highestnumber = scorelist[i];
} else {
highestnumber = scorelist[i + 1];
}
}
setText("scoretext", (scorelist + " ") + namelist);
}
This is a fairly simple click button game and I have a loop which increases the score after each click, different amounts depending on how much the score currently is.
onEvent("clickbutton", "click", function( ) {
setProperty("gamescreen", "background-color", rgb(randomNumber(1, 250), randomNumber(1, 250), randomNumber(1, 250), 0.5));
if (score < 10) {
level = 1;
setText("levelbutton", "level " + level );
score += 1;
setText("scorecounter", "Score = " + score);
changebutton("clickbutton");
changebutton("dontclickbutton");
}
else if ((score >= 10)) {
level = 2;
setText("levelbutton", "level " + level );
score += 2;
setText("scorecounter", "Score = " + score);
changebutton("clickbutton");
changebutton("dontclickbutton");
}
else if ((score >= 50)) {
level = 3;
setText("levelbutton", "level " + level );
score += 3;
setText("scorecounter", "Score = " + score);
changebutton("clickbutton");
changebutton("dontclickbutton");
}
});
The changebutton is a function that changes the background color and text color of whatever "button" is through in the parameter, but that's not the main point here. The function of "Endgame" is what I'm expereincing difficulties with, so here we go. "endgame" is called at least when the wrong button is clicked and when the time runs out, which ever happens during the game. And in my endgame function I have
setText("scoretext", (scorelist + " ") + namelist);
But what is displayed is a whole bunch of numbers, but what I want to be displayed is the list of scores from highest to lowest with the respective names lined up from the namelist. As a side point my start button takes the user input, sets it as a variable called "name" and appends to my namelist. This is an example of the results, I put in meir for name and that displayed ok, but my score was 5 and it showed up as
0,0,0,0,1,2,2,3,3,4,
4,5,5,5 meir
even though the only that should be in my scorelist is 5, so it shouldn't print out all the other stuff. So if I could get any help on to properly sort the scorelist, and have it only print out the scores, and not whole bunch of numbers that would be great, and prefferably have it print out the names in order with the scores from highest scoring names to lowest scoring names, that would be great. Thanks in advance.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)