Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Spring Thunder Javascript

I don’t understand how do you do this.

A blue gem has a value of 10.
// Collect if item.type is equal to “gem”
// AND item.value is equal to 10.

1 Like

how do you find the value

1 Like

I copied what says above about the coin and pasted it below.

1 Like

then i changed the place that says coin to gem and the value from 2 to 10.

1 Like

I don’t get why it still doesn’t work

1 Like

It says I ran out of time

1 Like

if(item.type == "gem" && item.value == 10 )

AND in javascript is “&&”

2 Likes

In javascript, “and” is used as “&&.” Also, to set the gem’s value for a given number (in your case, 10), use the code “item.value == 10”

1 Like

It still says I ran out of time

1 Like

This is my code for the spring thunder level.

1 Like

// Certain coins and gems attract lightning.
// The hero should only grab silver coins and blue gems.

while (true) {
var item = hero.findNearestItem();
// A silver coin has a value of 2.
// Collect if item.typ is equal to “coin”
// AND item.value is equal to 2.
if (item.type == “coin” && item.value == 2) {
hero.moveXY(item.pos.x, item.pos.y);
}
// A blue gem has a value of 10.
// Collect if item.type is equal to “gem”
// AND item.value is equal to 10.
if(item.type == “gem” && item.value == 10 ) {
hero.moveXY(item.pos.x, item.pos.y);
}
}

1 Like

This is the code i wrote for the spring thunder without the excess words that are on the pad at the beggining.

1 Like

while (true) {
var item = hero.findNearestItem();
if (item.type == “coin” && item.value == 2) {
hero.moveXY(item.pos.x, item.pos.y);
}
if(item.type == “gem” && item.value == 10 ) {
hero.moveXY(item.pos.x, item.pos.y);
}
}

2 Likes

It worked I just needed faster boots thank you.

1 Like

your code is hard to read.

Edit your post with code, select code and click button

it will automatically make it looks good

also maybe you computer or browser is too slow for CodeCombat.
Fastest I think is Chrome

1 Like

I use chrome radchenko

1 Like

while (true) {
var item = hero.findNearestItem();
// A silver coin has a value of 2.
// Collect if item.typ is equal to “coin”
// AND item.value is equal to 2.
if (item.type == “coin” && item.value == 2) {
hero.moveXY(item.pos.x, item.pos.y);
}
// A blue gem has a value of 10.
// Collect if item.type is equal to “gem”
// AND item.value is equal to 10.
if(item.type == “gem” && item.value == 10 ) {
hero.moveXY(item.pos.x, item.pos.y);Preformatted text

1 Like

do you mean like this

1 Like

select code ----> click that button.

while (true) {
var item = hero.findNearestItem();
   // A silver coin has a value of 2.
   // Collect if item.typ is equal to "coin"
   // AND item.value is equal to 2.
if (item.type == "coin" && item.value == 2) {
hero.moveXY(item.pos.x, item.pos.y);
}
   // A blue gem has a value of 10.
   // Collect if item.type is equal to "gem"
   // AND item.value is equal to 10.
if(item.type == "gem" && item.value == 10 ) {
hero.moveXY(item.pos.x, item.pos.y);

code looks like this ^

1 Like

ok i understand mr Radchenko

1 Like