#computer science class help pls

7 messages · Page 1 of 1 (latest)

quick viper
#

my teacher says that i need to make a loop and a list or i wont pass and i made a slot machine and its on code.org can someone please help

var cash = 1000;
setText("money", cash);

onEvent("spin", "click", function() {

var bet = getNumber("bet");

var num1 = randomNumber(1,3);
var num2 = randomNumber(1,3);
var num3 = randomNumber(1,3);


if(bet <= cash) {
  if(num1 == 1) {
    setImageURL("img1","slotmachineapple.jpg");
  }
  
  else if(num1 == 2) {
    setImageURL("img1","slotmachineorange.png");
  }
  
  else {
    setImageURL("img1","slotmachinemango.png");
  }
  
  if(num2 == 1) {
    setImageURL("img2","slotmachineapple.jpg");
  }
  
  else if(num2 == 2) {
    setImageURL("img2","slotmachineorange.png");
  }
  
  else {
    setImageURL("img2","slotmachinemango.png");
  }
  
  if(num3 == 1) {
    setImageURL("img3","slotmachineapple.jpg");
  }
  
  else if(num3 == 2) {
    setImageURL("img3","slotmachineorange.png");
  }
  
  else {
    setImageURL("img3","slotmachinemango.png");
  }
  
  if(num1 == num2 && num2 == num3) {
    cash = cash + bet * 2;
  }
  
  else {
    cash = cash - bet;
  }
  
  setText("money", cash);
}

else {
  
 setText("money", "INSUFFICIENT FUNDS");
}

});
onEvent("atm", "click", function() {
cash = cash + 100;
setText("money", cash);
});

sly haloBOT
#

This post has been reserved for your question.

Hey @quick viper! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

sly haloBOT
signal hatchBOT
#

var cash = 1000;
setText("money", cash);

onEvent("spin", "click", function() {
     
   var bet = getNumber("bet");
   
   var num1 = randomNumber(1,3);
   var num2 = randomNumber(1,3);
   var num3 = randomNumber(1,3);
   
   
   if(bet <= cash) {
     if(num1 == 1) {
       setImageURL("img1","slotmachineapple.jpg");
     }
     
     else if(num1 == 2) {
       setImageURL("img1","slotmachineorange.png");
     }
     
     else {
       setImageURL("img1","slotmachinemango.png");
     }
     
     if(num2 == 1) {
       setImageURL("img2","slotmachineapple.jpg");
     }
     
     else if(num2 == 2) {
       setImageURL("img2","slotmachineorange.png");
     }
     
     else {
       setImageURL("img2","slotmachinemango.png");
     }
     
     if(num3 == 1) {
       setImageURL("img3","slotmachineapple.jpg");
     }
     
     else if(num3 == 2) {
       setImageURL("img3","slotmachineorange.png");
     }
     
     else {
       setImageURL("img3","slotmachinemango.png");
     }
     
     if(num1 == num2 && num2 == num3) {
       cash = cash + bet * 2;
     }
     
     else {
       cash = cash - bet;
     }
     
     setText("money", cash);
   }
   
   else {
     
    setText("money", "INSUFFICIENT FUNDS");
   }
});
onEvent("atm", "click", function() {
   cash = cash + 100;
   setText("money", cash);
}); ```

This message has been formatted automatically. You can disable this using /preferences.

compact osprey
#

Do you know arrays?

#

Do you know what loops are?