Skip to content

codelawer/errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 

Repository files navigation

Errors

Errors will keep JS from executing your code. This is not the goal of programming, so here's some errors to practice fixing.

Complete these exercises directly in the browser from your fork of this repo. (We've provided some completed examples for you to get the idea):

  1. Paste the broken code into the devtools console and run it
  2. Copy-paste the error message into the "error message" space the challenge
  3. Classify the error: Creation or Execution and Syntax or Semantic
  4. Fix the error and paste your fixed code into "the fix" section of the challenge

Practice using the devtools by clicking on the 'VM##:#' link to the right of the error message. Devtools will automatically open the source code and highlight where the error appears. With these super simple examples this feature may feel like overkill, but you will appreciate it's help once you move on to the next set of exercises.

Index:



Learning Objectives

  • reading & identifying error messages
  • finding and fixing syntax errors
  • building a personal error+fix reference
  • not logic errors, that's for 'debugging'
  • using devtools console
  • writing markdown directly from github

Exercises

malformed while loop

broken code:

let value = 0;
while (value < 9) 
  value++;
};

error message:

Uncaught SyntaxError: Unexpected token }

classification:

  • creation phase
  • syntax

the fix:

let value = 0;
while (value < 9) {
  value++;
};

your notes:

TOP


missing variable name

broken code:

var = 5;

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


too-far object access

broken code:

let a = {b:3};
let b = a.b.3

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


access property directly

broken code:

let x = {b:'e'};
let y = b.e;

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


improper multi-line string

broken code:

let a = 'this is 
two lines';

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


improper end of statement

broken code:

let a = 1:

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


malformed array

broken code:

let myArray = [1, 2, 3;

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


missing arguments

broken code:

function getNine {
  let x = 6;
  let y = 3;
  return x + y;
}
let result = getNine();

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


improper nested quotes 1

broken code:

let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


improper nested quotes 2

broken code:

let nested_messages = 'remind yourself ''i can do this!'' at least once a day';

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


reassigning to constant

broken code:

const a = 9;
a = 0;

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


unassigned const declaration

broken code:

const a;
a = 0;

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP


is not a function

broken code:

let array = [];
array.length()

error message:

classification:

  • creation phase or execution phase ?
  • syntax or semanitc ?

the fix:

your notes:

TOP



About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors