CSD Unit 3 Lesson 24 Level 10

Hello. I’m trying to figure out how to completely make CS Discoveries Unit 3 Lesson 24 Level 10 work completely (https://studio.code.org/s/csd3-2020/stage/24/puzzle/10?section_id=3101255). I have all but the last part working, where a random scene is to be programmed in if the score reaches 10. All but the scene changing at the correct time seems to be working. My code and screenshots are below. Please help me make this work so I can help my students.

var coin = createSprite(200,10);
coin.setAnimation(“coin_gold_1”);
setCoin();

var bunny = createSprite(200,350);
bunny.setAnimation(“bunny1_ready_1”);

var score = 0;

function draw() {
background(“white”);

if(keyDown(“left”)){
bunny.x = bunny.x - 2;
}

if(keyDown(“right”)){
bunny.x = bunny.x + 2;
}

if(coin.y > 400){
setCoin();
}
if (bunny.isTouching(coin)) {
score = score + 1;
setCoin();
if (score = 10) {
setBackground();
} else {
background(“white”);
}
}

textSize(20);
text("Score: " + score, 10, 10, 100, 100);
drawSprites();
}

function setCoin(){
coin.y = 50;
coin.x = randomNumber(10, 390);
coin.velocityY = 2;
}
function setBackground() {
if (score < 10) {
background(“white”);
} else {
var backGround = createSprite(200, 200);
backGround.setAnimation(“background_landscape28_1”);
}
}

I edited my post to remove any answers that might give too much away to a student who stumbles on this one. :blush:

One other thing to look at in your code is the line where you ask if (score=10) {

After a conditional statement (if), you need a double =

if (score==10) {

A single = tells it to assign the score of 10 to your score, so your score is automatically jumping to 10 the first time it runs that code.

Mike

Awesome! Funny, I figured out my error yesterday while helping a student, so that was good.

I love how you added a random velocity to the coin! So fun!