Sample Video Frame
06: Escape Sequences
This exercise will be a puzzle exercise. What I mean by this is I'm going to give you the code without much explanation, and with a few errors, and then you have to figure out how to fix it. It's only about four lines of code, so you should be able to make it work. If you can't, then go watch the video to see how I did it.
The Code
I recommend you study the first two lines to figure out what I'm doing and then try to fix the next two lines. I will periodically do these puzzle exercises so you get used to fixing broken code. Trust me, the world of programming is full of nothing but broken code.
let talking = "I'm not sure if she said, \"Hello\" or not.";
let walking = 'I\'ll need to go \'cause you don\'t know.';
// These strings are broken. Use escapes to fix them.
let height = "6'2"";
console.log('I'm not g'na see y'all for a while.');
What You Should See
What you will see here is how the code looks if you try to run it without fixing it. This code is meant to include an error on purpose. I am showing you the error so that way when you encounter it on your first run you know that it's supposed to be this way.
$ node ex06-fail.js
ex06-fail.js:5
let height = "6'2"";
SyntaxError: Invalid or unexpected token
at new Script (vm.js:74:7)
at createScript (vm.js:246:10)
at Object.runInThisContext (vm.js:298:10)
at Module._compile (internal/modules/cjs/loader.js:646:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
$
Remember that the solution is in the video. That way you can attempt this exercise and then see if you did it right or get clues from the video.
Learn JavaScript Today
Register today for the Early Access course and get the all currently available videos and lessons, plus all future modules for no extra charge.
Still Not Sure? Try the next FREE Lesson!