Binary Agents get help

my new string is unassigned to a variable or something.
who writes this stuff what happens to simple English.
anywho. its wrong and it works in Repl.it.

Your code so far


[spoiler]
function binaryAgent(str) {
  newString = str.split(' ');
  answer = [];
  


   for(i=0;i < newString.length;i++){
   answer.push(String.fromCharCode(parseInt(newString[i], 2))); 
  }

  return answer.join('');
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0.

Link to the challenge:


[/spoiler]

You just need to define the variables newString, answer, and i using something like var or let.
-J

function binaryAgent(str) {
  let newString = str.split(' ');
  let answer = [];
  


   for(let i=0;i < newString.length;i++){
   answer.push(String.fromCharCode(parseInt(newString[i], 2))); 
  }

  return answer.join('');
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");

The error message is pretty clear if you think about it, “not defined”. Meaning it can’t find the identifier.

It’s like if I spoke a sentence to you and used a non-existing word, like “Hey royalgreen50 how are heifhiefhijf”. Your brain would get to “heifhiefhijf” and not find the definition of the word in its memory and “throw an error”. The engine will throw a Reference Error Uncaught ReferenceError: heifhiefhijf is not defined because it can’t find the definition for heifhiefhijf anywhere.

The reason why it works in some environments is that JavaScript will try to be “helpful” by automatically making the identifier global and put it on the global object.

function JSPleaseHelp() {
  notTheRightWay = 'silliness';
  return notTheRightWay;
}

JSPleaseHelp()
"silliness"

/* notTheRightWay is now on the global object, in this case, the window object */
window.notTheRightWay
"silliness"

If you set the 'use strict' directive it will error out instead

function JSPleaseDoNotHelp() {
  'use strict'
  notTheRightWay = 'silliness';
  return notTheRightWay;
}

JSPleaseHelp()
Uncaught ReferenceError: notTheRightWay is not defined

BTW, the guide article has been updated on master but the site has not yet been updated. You have to be a bit careful about copying some of the guide article code, they are not all correct anymore. At least not until the update.

1 Like