Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active February 7, 2023 18:48
Show Gist options
  • Save acidtone/b9aaf4228a903796a6d8532ffb36d9d7 to your computer and use it in GitHub Desktop.
Save acidtone/b9aaf4228a903796a6d8532ffb36d9d7 to your computer and use it in GitHub Desktop.
JS Activity: Bug hunt - syntax errors

JS Activity: Bug hunt - syntax errors

Overview

The code in script.js has syntax errors. Hunt them down and fix them!

Instructions

  1. Run the code in script.js (see below);
  2. Check the console/terminal for errors;
  3. Find the line number of the error;
  4. Using your knowledge of js variables, fix the problems so the file runs without error.

Note: there might also be a logic error in the code!

Running this code

Browser

To run script.js from the browser:

  1. Download or clone this Gist into your workspace;

  2. In this new directory, create a valid index.html file;

  3. In the <head> of index.html, link to script.js with a <script> tag:

    <script src="script.js" type="module">
  4. Run index.html in the browser of your choice;

  5. Open the Web Console to view the output.

Node

Alternatively, if you have Node installed, script.js can be run from the command line:

  1. Download or clone this Gist into your workspace;
  2. Navigate to this directory from the command line;
  3. Run the file using Node: $ node script.js
/**************************/
/* Example: Calculate GST */
/**************************/
subTotal = 40;
total = subTotal * 0.05 + subTotal;
console.log(`$${subTotal} plus GST is $${total}.`);
/****************************/
/* Example: Square a number */
/****************************/
const num = 4;
const numSquared = num * num;
console.log(`${Num} squared is ${numsquared}.`);
/**********************************************/
/* Example: Calculate fahrenheit from celsius */
/**********************************************/
const tempF = 72;
const tempPreference = 'celsius';
const temp;
if (tempPreference == 'celsius') {
temp = (5 / 9) * (tempF - 32)
} else {
temp = tempF;
}
console.log(`Temp is ${temp} degrees`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment