Sample Video Frame

Created by Zed A. Shaw Updated 2024-02-17 04:54:36

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.

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
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)

Do your best to solve this error, and be sure to Google this message to find more information.

Previous Lesson Next Lesson

Register for Learn JavaScript the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.