# Wishing well Help Javascript

var less = “Nimis”;
var more = “Non satis”;
var requiredGold = 104;

// This function calculates the sum of all coin values.
function sumCoinValues(coins) {
var coinIndex = 0;
var totalValue = 0;
// Iterate all coins.
while (coinIndex < coins.length) {
totalValue += coins[coinIndex].value;
coinIndex++;
}
}

function collectAllCoins() {
var item = hero.findNearest(hero.findItems());
while (item) {
hero.moveXY(item.pos.x, item.pos.y);
item = hero.findNearest(hero.findItems());
}
}

while (true) {
var items = hero.findItems();
// Get the total value of coins.
var goldAmount = sumCoinValues(items);
// If there are coins, then goldAmount isn’t zero.
if (goldAmount !== 0) {
// If goldAmount is less than requiredGold
// Then say “Non satis”.
if (goldAmount < requiredGold){
hero.say(less);
}
// If goldAmount is greater than requiredGold
if (goldAmount > requiredGold){
// Then say “Nimis”.
hero.say(more);
}
// If goldAmount is exactly equal to requiredGold
if (goldAmount == requiredGold){
// If there is exactly 104 gold, then collect all coins.
CollectAllCoins();
}
}
hero.moveXY(items.pos.x,items.pos.y);

``}``

Oh sorry I meant <var less = “Nimis”;
var more = “Non satis”;
var requiredGold = 104;

// This function calculates the sum of all coin values.
function sumCoinValues(coins) {
var coinIndex = 0;
var totalValue = 0;
// Iterate all coins.
while (coinIndex < coins.length) {
totalValue += coins[coinIndex].value;
coinIndex++;
}
}

function collectAllCoins() {
var item = hero.findNearest(hero.findItems());
while (item) {
hero.moveXY(item.pos.x, item.pos.y);
item = hero.findNearest(hero.findItems());
}
}

while (true) {
var items = hero.findItems();
// Get the total value of coins.
var goldAmount = sumCoinValues(items);
// If there are coins, then goldAmount isn’t zero.
if (goldAmount !== 0) {
// If goldAmount is less than requiredGold
// Then say “Non satis”.
if (goldAmount < requiredGold){
hero.say(less);
}
// If goldAmount is greater than requiredGold
if (goldAmount > requiredGold){
// Then say “Nimis”.
hero.say(more);
}
// If goldAmount is exactly equal to requiredGold
if (goldAmount == requiredGold){
// If there is exactly 104 gold, then collect all coins.
CollectAllCoins();
}
}
hero.moveXY(items.pos.x,items.pos.y);

``````}
``````

Oops another sorry here is my code `var less = “Nimis”;
var more = “Non satis”;
var requiredGold = 104;

// This function calculates the sum of all coin values.
function sumCoinValues(coins) {
var coinIndex = 0;
var totalValue = 0;
// Iterate all coins.
while (coinIndex < coins.length) {
totalValue += coins[coinIndex].value;
coinIndex++;
}
}

function collectAllCoins() {
var item = hero.findNearest(hero.findItems());
while (item) {
hero.moveXY(item.pos.x, item.pos.y);
item = hero.findNearest(hero.findItems());
}
}

while (true) {
var items = hero.findItems();
// Get the total value of coins.
var goldAmount = sumCoinValues(items);
// If there are coins, then goldAmount isn’t zero.
if (goldAmount !== 0) {
// If goldAmount is less than requiredGold
// Then say “Non satis”.
if (goldAmount < requiredGold){
hero.say(less);
}
// If goldAmount is greater than requiredGold
if (goldAmount > requiredGold){
// Then say “Nimis”.
hero.say(more);
}
// If goldAmount is exactly equal to requiredGold
if (goldAmount == requiredGold){
// If there is exactly 104 gold, then collect all coins.
CollectAllCoins();
}
}
hero.moveXY(items.pos.x,items.pos.y);

``````}
``````

`

1 Like

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

can you send us a link to the level @H_G

Hi H_G,

I think the problem is just one letter is capitilised when it shouldn’t be. When you write the function for collecting coins you put:

but when you call it you put:

Cheers,

Jenny

1 Like

Hi @H_G, and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

Yes, I think Jenny is right, you need to change the function calling from CollectAllCoins(); to collectAllCoins();

Thank you! I passed the level!

You’re welcome!!! (It was mostly @jka2706, I just checked)