21 Day Coding Challenge

Challenge 8 - HELP PLS

#1

i am confused about the update done regarding challenge 8

What I did is here, and I do not see why this isnt the answer.

Does anyone know why ?

Thanks in advance

//day 8

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

loadModule(findModuleIndex("communication"));
#2

It wasnā€™t confirmed yet, but based on some sample code Iā€™m trying to run through, I believe the validation of Challenge #8 might still be having issues. That being said, Iā€™m not entirely sure about this part of your codeā€¦

function loadModule(index){
  if(availableModules[index].hasOwnProperty(ā€˜essentialā€™) ) {
    availableModules[index].essential === true; // ???
  }
  availableModules[index].enabled = true;
  ship.modules.push(availableModules[index]);
}

Is it really a === youā€™re looking for? Could you tell me why?

#3

Hi @nathalia

availableModules[index].essential === true;
Is your culprit!
That does not set anything. It just checks.
Should be availableModules[index].essential = true;

1 Like
#4

Hi, guys

Thank you so much, both of you.

What I added now, was

[ā€¦]
resetLARRY();

//day 8

function loadModule(index){

if(availableModules[index].hasOwnProperty('essential') )

{

availableModules[index].essential === true;

}
}

loadModule(findModuleIndex(ā€œcommunicationā€));


However, nothing has changed

#5

Although it looks like you want to do an assignment, you use ===, which is used for comparisonā€¦

I assume you didnā€™t post the whole thing, right? For you didnā€™t push and you didnā€™t set the enabled propertyā€¦

#6

function powerOn(){
ship.powerOn = true;
}

//day 2

function countModules(){
return availableModules.length;
}

//day 3

function countEssential() {

const newArray = [];

for(var i = 0; i < availableModules.length; i++){
if(availableModules[i].essential === true){
newArray.push(1);
}
}

return newArray.length;
}

//day 4

index = 0;

  for(let i = 0; i < availableModules.length; i++ ){
    if(availableModules[i].name === "life-support"){
      availableModules[i].enabled = true;
      index = i;
    }
  }


function loadModule(index){
 
  ship.modules = availableModules.slice(index,index+1);
  

} 

loadModule(index);

//day 5

function loadModule(index){

availableModules[index].enabled = true;
ship.modules.push(availableModules[index]);
}

function findModuleIndex(moduleName){
for(var i =0 ; i < availableModules.length ; i++){
if (availableModules[i].name == moduleName && availableModules[i].essential){
return i;
}
}
}

loadModule(findModuleIndex(ā€œpropulsionā€));
loadModule(findModuleIndex(ā€œlife-supportā€));
loadModule(findModuleIndex(ā€œpropulsionā€));

//day 6

loadModule(findModuleIndex(ā€œnavigationā€));

//day 7
function resetLARRY(){

for(var i =0 ; i <10; i++){
LARRY.quack();
}
}
resetLARRY();

//day 8

function loadModule(index){

if(availableModules[index].hasOwnProperty('essential') )

{
availableModules[index].essential = true;
}
}

loadModule(findModuleIndex(ā€œcommunicationā€));

#7

Hoo you seem to have 2 loadModule functionsā€¦ In exercise 8, you update the one you had with new things to take into accountā€¦

#8

Hi, Seb

In one of the help post, @brandinchiu said that we were not supposed to modify the original code

I am very confused.

#9

Now Iā€™m confusedā€¦ If you declare twice the same function, itā€™ll most likely give you an error about the function being already declared. Perhaps you could try to save to a text file what you already have and update itā€¦

Could you see a way to do this:

function loadModule(index){
  availableModules[index].enabled = true;
  ship.modules.push(availableModules[index]);
}

But to also do this in it?:

if(availableModules[index].hasOwnProperty('essential') ) {
  availableModules[index].essential = true;
}

If so, modify it and keep just one version of that function. Let us know how if it ends up working :four_leaf_clover:

Alsoā€¦ I see twice this line:

loadModule(findModuleIndex("propulsion"));

This could be another source of problemā€¦ So far, the order seemed to also matter, so you might want to follow this order:

loadModule(findModuleIndex("life-support"));
loadModule(findModuleIndex("propulsion"));
loadModule(findModuleIndex("navigation"));
#10

I will work on it

I tried to find where he said to not alter the older code. But I cant

Thank you guys, I will work on this

#11

Still nothing

function powerOn(){
ship.powerOn = true;
}

//day 2

function countModules(){
return availableModules.length;
}

//day 3

function countEssential() {

const newArray = [];

for(var i = 0; i < availableModules.length; i++){
if(availableModules[i].essential === true){
newArray.push(1);
}
}

return newArray.length;
}

//day 4

index = 0;

  for(let i = 0; i < availableModules.length; i++ ){
    if(availableModules[i].name === "life-support"){
      availableModules[i].enabled = true;
      index = i;
    }
  }


function loadModule(index){
  ship.modules.enabled = true;
  ship.modules = availableModules.slice(index,index+1);

} 

loadModule(index);

//day 5
function loadModule(i){

if(availableModules[index].hasOwnProperty(ā€˜essentialā€™) ) {
availableModules[index].essential = true;
}
availableModules[i].enabled=true;
ship.modules.push(availableModules[i]);
}

function findModuleIndex(name){
for(var j=0; j<availableModules.length; j++){
if(availableModules[j].name===name
// && availableModules[index].name===name)
)
{
return j;

}

}
}

loadModule(findModuleIndex(ā€œpropulsionā€));
loadModule(findModuleIndex(ā€œlife-supportā€));

//day 6

loadModule(findModuleIndex(ā€œnavigationā€));

//day 7
function resetLARRY(){

for(var i =0 ; i <10; i++){
LARRY.quack();
}
}
resetLARRY();

//day 8

loadModule(findModuleIndex(ā€œcommunicationā€));

#12

I sent you an answer here:

#13

Hi,
I had to go to work today, so I will look into the code just now.

I REALLY APPRECIATE the help you have given me.

I will work hard, and I let you know how it goes.

Once again, thank you

1 Like