This is some of the code from a student’s project, the object of the code is to capture how many hits he has on a game. The problem is the code is not generating the right information. Any ideas would be greatly appreciated.
Here’s the code:
var score;
var moleArray = [“mole1”, “mole2”, “mole3”, “mole4”, “mole5”, “mole6”, “mole7”, “mole8”, “mole9”, “mole10”];
setScreen (“welcomeScreen”);
onEvent(“playButton”, “click”, function(){
setScreen(“gameScreen”);
setProperty(“mole1”, “hidden”, true);
setProperty(“mole2”, “hidden”, true);
setProperty(“mole3”, “hidden”, true);
setProperty(“mole4”, “hidden”, true);
setProperty(“mole5”, “hidden”, true);
setProperty(“mole6”, “hidden”, true);
setProperty(“mole7”, “hidden”, true);
setProperty(“mole8”, “hidden”, true);
setProperty(“mole9”, “hidden”, true);
setProperty(“mole10”, “hidden”, true);
});
function updateScreen(){
setText(“total_score”, score);
setProperty(“total_score”,“text”,score);
}
function displayMole(){
var num = (Math.random() * 9);
document.canvas.src = moleArray[num];
console.log(num);
}
//test button
onEvent (“genMole”, “click”, function(){
displayMole;
});
//clicking mole
onEvent (“mole1”, “click”, function(){
setProperty(“mole1”, “hidden”, true);
score = score + 1;
updateScreen;
});
Student has used various websites that lead to incorrect functions to be used in the Design Mode. High School Freshman.
Original Link:
Unit 5 CSP Lesson 3
Student has not tried anything to repair code.
The app is supposed to allow users to whack a mole, the program uses a button that has to be clicked several times. The student would like the app to record how many hits a player takes before they win the game. The app should record the number of hits and refresh the score on the screen. Right now, it does nothing.