21 Day Coding Challenge

Challenge #4 Help?

#1

Hey gang,

I’ve been stuck on challenge 4 for a while and I can’t figure out what’s wrong with my code. It’s saying that it runs, it’s just not producing the correct result.

function loadModule(index) {
if (availableModules[index].essential === true) {
availableModules[index].enabled = true;
ship.modules.push(availableModules[index]);
} else {
return null;
}
}

function loopModule() {
for (var i; i < 8; i++) {
if (availableModules[i].name == “life-support”) {
loadModule(i);
}
}
}

loopModule();

Any help would be much appreciated!

#2

Hi Duncan,
I’ll point you towards what I suspect is causing you issues:

for (var i; i < 8; i++) {

There’s 2 “errors” in that line… :slight_smile:

The rest seemed to be ok.

Let us know if you need more hints. :four_leaf_clover:

1 Like
#3

I’m thinking your var i needs to have a value assigned to it and your i needs to be less than the length of the available modules.

1 Like
#4

Got it!! Thanks Seb :slight_smile:

1 Like