in Education by
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)

1 Answer

0 votes
by
Someone saw my code and pointed out at least part of the issue. One of the ways the "endgame" function starts is when the time == 0, and I have in my "endgame" function the following. ismytimergoing = false; appendItem(scorelist, score); so I think ismytimergoing = false; stops the timer, but that happens when the timer == 0 so the endgame function is keep on happening constantly increasing the scorelist size making it print out a lot of numbers. so I changed the endgame function to be the following. function endgame() { setScreen("scorescreen"); ismytimergoing = false; seconds = 60; 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); } I changed the endgame function, so now even if it happens because of the timer turning to zero, the seconds are reset and it's only run once, thus making the scorelist a much easier thing to deal with.

Related questions

0 votes
    d. Arrange the following operators from the lowest to the highest precedence. != % && ++ Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    Amount of matter and energy from the lowest level to the highest level. (a) decreases (b) ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    I am trying to return an javascript value with Awesome lib in Vb.net / C#. Now I know how to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have created a partial view, the element in the partial view looks like this (Razor Code): @Html ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I have created a partial view, the element in the partial view looks like this (Razor Code): @Html ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    The denominator polynomial in a transfer function may not have any missing terms between the highest and the lowest ... EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
0 votes
    The denominator polynomial in a transfer function may not have any missing terms between the highest and the lowest ... EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 12, 2021 in Education by JackTerrance
0 votes
    There are loads of questions about the current date in JavaScript in general, but in my scenario, I have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    I am attempting to solve a problem where if the elements in one array are squared, and all of the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I write a lot of dynamically generated content (developing under PHP) and I use jQuery to add extra ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am trying to sort an array of objects by the name field but the ordering is wrong. The order I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    Different JavaScript Questions and Answers...
asked Sep 17, 2022 in Technology by Editorial Staff
...