21 Day Coding Challenge

Challenge 21 should work, unkown problem

#1

Hi im unsure what the problem is here, this is the entire code (I removed the previous bits when I saw it wasnt working) I cant figure out what isnt working

function decodeMessage(message) {
  message=message
  .replace(/1/g,'i')
  .replace(/2/g,'u')
  .replace(/3/g,'e')
  .replace(/4/g,'a')
  .replace(/5/g,'y')
  .replace(/0/g,'o');
  return message;
}
function returnToEarth() {
  var xMessage = broadcast('x');
  var yMessage = broadcast('y');
  var zMessage = broadcast('z');
  var xPos = decodeMessage(xMessage);
  var yPos = decodeMessage(yMessage);
  var zPos = decodeMessage(zMessage);
  navigation.x = parseInt(xPos, 16);
  navigation.y = parseInt(yPos, 16);
  navigation.z = parseInt(zPos, 16);
}
returnToEarth();
#2

What’s the error you’re getting?

#3

its the standard error for not solving the challence (code ran)

#4

Yesterday, I’ve worked on a code where the issue was really in the calibrate() function, they seem to be testing everything so the issue might not be in that part of your code… :thinking:

Would you share the part related to calibrate x, y and z, please? We’ve started sharing solutions, so it’s not that much of an issue, anymore, if you share code that should be valid.

#5

ive removed all the rest of the code… does that mean I still have to have other functions running or otherwise existing?

#6

I believe so… From our tests from yesterday, you might need most of your code. We didn’t test enough to know exactly what’s needed and what’s not, but when the person removed everything, it didn’t work. When all the code was there, it did. :sunny:

#7
function powerOn() {
  ship.powerOn = true ;
}
function countModules() {
  return availableModules.length;
}
function countEssential(){ 
  var essentialModuleCount = 0, i; 
  for (i = 0; i < countModules(); i++) {
    if (availableModules[i].essential === true) 
    essentialModuleCount++;
  }
  return essentialModuleCount;
}
function loadModule(index) {
  availableModules[index].enabled = true;
  ship.modules.push(availableModules[index]);
}
function findModuleIndex(moduleName) {
 var i;
 for (i = 0; i < countModules(); i++ ) {
    if (availableModules[i].name == moduleName) {
      return i;
    }
  }  
}
loadModule(findModuleIndex("life-support"));
loadModule(findModuleIndex("navigation"));
function resetLARRY() {
  var i;
  for (i = 0; i < 10; i++) {
    LARRY.quack();
  }
}
resetLARRY();
loadModule(findModuleIndex("communication"));
function setMessage() {
  radio.message = JSON.stringify(navigation);
}
setMessage();
function activateBeacon() {
  radio.beacon = true;
}
activateBeacon();
function setFrequency() {
  radio.frequency = (radio.range.low + radio.range.high) / 2;
}
function initialize() {
  navigation.x = navigation.y = navigation.z = 0;
}
function calibrateX() {
  var i, signal;
  for (i = 1; i <= 12; i++) {
    signal = checkSignal();
    if (signal !== undefined) {
      navigation.x = signal;
      break;
    }
  }
}
function calibrateY() {
  var i, signal;
  for (i = 1; i <= 60; i++) {
    signal = checkSignal();
    if (signal !== undefined) {
      navigation.y = signal;
      break;
    }
  }
}
function calibrateZ() {
  var i, signal;
  for (i = 1; i <= 60; i++) {
    signal = checkSignal();
    if (signal !== undefined) {
      navigation.z = signal;
      break;
    }
  }
}
function calibrate() {
  calibrateX();
  calibrateY();
  calibrateZ();
}
function setSpeed(speed) {
  speed = parseInt(speed);
  if (speed >= 0) {
    navigation.speed = speed;
  }
}
function activateAntenna() {
  ship.antenna.active = true;
}
activateAntenna();
function sendBroadcast() {
  var i;
  for (i = 0; i <= 99; i++) {
    broadcast();
  }
}
sendBroadcast();
function decodeMessage(message){
  message=message
  .replace(/1/g,'i')
  .replace(/2/g,'u')
  .replace(/3/g,'e')
  .replace(/4/g,'a')
  .replace(/5/g,'y')
  .replace(/0/g,'o');
  return message;
}
function returnToEarth() {
  var xMessage = broadcast('x');
  var yMessage = broadcast('y');
  var zMessage = broadcast('z');
  var xPos = decodeMessage(xMessage);
  var yPos = decodeMessage(yMessage);
  var zPos = decodeMessage(zMessage);
  navigation.x = parseInt(xPos, 16);
  navigation.y = parseInt(yPos, 16);
  navigation.z = parseInt(zPos, 16);
}
returnToEarth();

this is the whole thing, but it seems you arent able to test solutions anymore? im not getting any feedback as to wether or not its proprely solving it

#8

I reloaded and it worked, seems I was logged out for some reason

1 Like
#9

Did the code work? Or were you just able to test a solution?

Everything seems ok with your code… :thinking:

#10

it did work but only after refreshing the page (I literally copied the code before refreshing) it appears i had been logged out somehow

#11

Hooo I see, strange… Thank you for the update :slight_smile: