Rabbit Racer Challenge: Advanced JS
Hi,
I really need help on Step 1 of this challenge. Thanks!
Hi,
I really need help on Step 1 of this challenge. Thanks!
Hi Shamu,
The goal for Step 1 is to create a new button object and draw it on the screen beneath the rabbit on the far right.
If you look at line 116, there's a variable named btn1, but it hasn't been assigned to anything! We want to create a new button object and assign it to btn1. At the top of the code, you can see the button object and its constructor. The constructor takes in a configuration object that it uses to set the new button's properties.
Here's another example:
var Card = function(config) {
this.x = config.x || 0;
this.y = config.y || 0;
this.width = config.width || 50;
this.height = config.height || 90;
this.suit = config.suit || "Hearts";
this.value = config.value || "3";
};
The above code is a constructor that creates a playing card object and accepts a configuration object as a parameter to set its properties. If we wanted to create a new playing card, we could do so like this:
var card1 = new Card({
suit: "Spades",
value: "King"
});
Note that we could also have created the configuration object separately and then passed it in using a variable name:
var card1Settings = {
suit: "Spades",
value: "King"
}
var card1 = new Card(card1Settings);
For the Rabbit Racer challenge, you need to create a button (just like the above example), except you'll be setting the 'x' and 'y' properties to position the button beneath the correct rabbit. You'll then draw the button on line 149 using the .draw() method attached to the Button object.
Hi , I'm Manas and I need help on step 3 so here is my code:
var btn1 = new Button ({
x: 342,
y: 340,
width:70,
height:56,
color: color(255, 0, 0),
label: "clicker",
onClick: function() {
rabbits[3].hop;
i have problem on onClick and it shows Did you mean to type pop instead of hop?
please give the correct code for onclick
Влезте в услугата, за да оставите коментар.