21 Day Coding Challenge

Challenge 19 help!

#1

Here is my code
function powerOn(){
if (ship.powerOn === false){
ship.powerOn = true;
}
}

function countModules(){
  var count = 0;
  
  for(var i=0; i<availableModules.length; i++){
    if(availableModules[i] !== 0){
      count += 1;
    }
  }
  return count;
}

function countEssential(){
  var count = 0;
  
  for (var i=0; i<availableModules.length; i++){
    if(availableModules[i].essential === true){
      count += 1;
    }
  }
  
  return count;
}

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

function loadLifeSupport(){
  for (var i=0; i<availableModules.length; i++){
    if (availableModules[i].name === "life-support"){
      loadModule(i);
    }
  }
}
loadLifeSupport();

function findModuleIndex(name){
  var ind = 0;
  for (var i=0; i<availableModules.length; i++){
    if (availableModules[i].name === name){
      ind = i;
    }
  }
  return ind;
}
loadModule(findModuleIndex("propulsion"));
loadModule(findModuleIndex("navigation"));

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

function findCommunication2(){
  for (var i=0; i<2; i++){
    loadModule(findModuleIndex("communication"));
  }
}
findCommunication2

function setMessage(){
  radio.message = JSON.stringify(navigation);
}
setMessage();

function activateBeacon(){
  if (radio.beacon === false){
    radio.beacon = true;
  }
}

function setFrequency(){
  var freq = (radio.range.low + radio.range.high)/2;
  radio.frequency = freq;
}

function initialize(){
  navigation.x = 0;
  navigation.y = 0;
  navigation.z = 0;
}

function calibrateX(){
  var signal;
  for (var i=0; i<12; i++){
    signal = checkSignal();
    if (signal !== undefined){
      navigation.x = signal;
    }
  }
}

function calibrateY(){
  var signal;
  for (var i=0; i<60; i++){
    signal = checkSignal();
    if (signal !== undefined){
      navigation.y = signal;
      break;
    }
  }
}

function calibrateZ(){
  var signal;
  for (var i=0; i<60; i++){
    signal = checkSignal();
    if (signal !== undefined){
      navigation.z = signal;
      break;
    }
  }
}

function calibrate(){
  calibrateX();
  calibrateY();
  calibrateZ();
}

function setSpeed(speed){
  var newSpeed = parseInt(speed, 10);
  if (newSpeed >= 0){
    navigation.speed = newSpeed;
  }
}

function activateAntenna(){
  if(ship.antenna.active !== null){
    ship.antenna.active = true;
  }
}

function sendBroadcast(){
  for (var i=0; i<100; i++){
    broadcast();
  }
}

function configureBroadcast(){
  setFrequemcy();
  activateAntenna();
  sendBroadcast();
}
#2

Hi Ava,
what’s the error message you’re getting?

Did you call configureBroadcast()? (I think you need to, this time around)

#3

…you’ll need to call your configureBroadcast() function to kick things off…

#4

If or once you call configureBroadcast(), you have a typo - “setFrequemcy” is spelled with an m instead of an n.

Secondly, earlier on in your script you’re trying to call “findCommunication2” but you aren’t including the brackets, so you’re not actually calling the function. Not sure if that’ll affect anything but you might want to try adding ‘()’ at the end if it still doesn’t work. It shouldn’t cause an error in and of itself though, it just won’t do anything

#5

you have frequen’m’cy in your code instead of frequency

#6

hey, why is it keep telling me that error :

i also tried with return as it mentioned here earlier on, but it didn’t work

#7

Did you keep your previous calls to these functions, in your code? (I don’t see anything wrong with what you have now, it might be somewhere else.)

#8

will it still work if i delete previous codes?

#9

I don’t think so… You most likely need those three functions, at the very least, and any dependency they might rely on (depending on how you’ve coded them).

1 Like
#10

wow okay i did that lol, thats probably why what can i do now? :smiley: do i need to write them all again?

#11

well i just used ava’s function since i erased mine :slight_smile: hope that is fine ! and ill keep a copy from now on!

1 Like
#12

Did it end up working?

1 Like
#13

it did thank you! it was because of me not having the previous codes! haha

1 Like