π Debugging Errors
Code not working? Follow the steps in the debugging process below before asking a peer or your teacher! Fixing your own errors, no matter how small, is one of the best ways to become a better coder.
π§± HTML Debugging Process
-
Check for Proper Tag Structure
- Every opening tag needs a closing tag:
<div> ... </div>
- Self-closing tags:
<img />
,<br />
,<input />
- Every opening tag needs a closing tag:
-
Check for Typos
- Misspelled tags wonβt work:
<boddy>
β<body>
- Misspelled attributes:
herf
βhref
,clas
βclass
- Misspelled tags wonβt work:
-
Check Nesting
- Tags must be properly nested: β
<p><strong>text</strong></p>
β<p><strong>text</p></strong>
- Tags must be properly nested: β
-
Check File Paths
- Are images or stylesheets loading? Check:
src="images/cat.jpg"
orhref="style.css"
- Are images or stylesheets loading? Check:
-
Use the Validator
- https://validator.w3.org to check for structural errors
π¨ CSS Debugging Process
-
Check Selectors
-
Make sure the selector matches the element:
- ID:
#main-header
β<h1 id="main-header">
- Class:
.card
β<div class="card">
- ID:
-
-
Check Property Spelling and Semicolons
- β
color: red;
βcolr red
or missing;
- β
-
Check File Links
- Did you link the stylesheet?
<link rel="stylesheet" href="style.css">
- Did you link the stylesheet?
-
Check Order and Specificity
- Inline styles override external ones
- More specific selectors override general ones
πͺ JavaScript Debugging Process
-
Check the Console for Errors
-
Read the first error and look for:
Uncaught ReferenceError
β variable not definedUncaught TypeError
β trying something on the wrong type
-
-
Check Capitalization and Spelling
- JS is case-sensitive:
document
βDocument
- Watch for typos like
getElemntById
- JS is case-sensitive:
-
Check Syntax
- Missing semicolons (
;
) - Matching
()
and{}
and[]
- Strings need quotes:
"text"
or'text'
- Missing semicolons (
-
Check If the Script Is Linked Properly
-
In your HTML:
- β
<script src="script.js"></script>
- Put it at the bottom of
<body>
, or usedefer
- β
-
-
Use
console.log()
Often- Print variable values to the console to check whatβs happening
- Example:
console.log(myVar);
-
Check DOM Selectors
- Does the element exist in the HTML?
- Use
document.querySelector("#id")
or.class
- If youβre getting
null
, check spelling and that the element is loaded