Hello!!
I need help again!
Link to the project or level: https://studio.code.org/projects/applab/frGJYjvYCobxBK9B1PjtaOBqjpVt6brf0-K2HiLfBkA
What I expect to happen: When the basketball is clicked text will appear at the top of the app showing how many balls I have collected (score) and how many lives I have left, if I have clicked the background.
What actually happens:
Right now, I have no count on the basketball no matter how many times I click the ball, the lives count down, but there is no score.
What I’ve tried: I have tried taking out the setText to hopefully create a counter on the basketball, but nothing is happening. I tried putting the code back into the program and am still not getting the results I was hoping to gain.
Here’s the code:
var score = 0;
var lives = 3;
setText(“total_score”,score);
setText(“number_lives”,lives);
onEvent(“start_button”, “click”, function() {
setScreen(“game_screen”);
});
onEvent(“basketball”, “click”, function() {
score = (score+1);
setPosition(“basketball”, randomNumber(200, 10), randomNumber(200, 10));
if (score == 10){
setScreen(“win_screen”);
}
});
onEvent(“background”,“click”,function(){
lives = (lives-1);
setText(“number_lives”, lives);
if (lives==0){
setScreen(“lose_screen”);
}
});
onEvent(“tryAgain_button”,“click”,function(){
setScreen(“welcome_screen”);
});
onEvent(“tryAgain_button”, “click”, function(){
setScreen(“welcome_screen”);
});
onEvent(“playAgain_button”, “click”, function() {
setScreen(“welcome_screen”);
});
Thank you for any help you may be able to offer.
Best,
Jennifer