Skip to content

Instantly share code, notes, and snippets.

@MisterBrash
Last active February 16, 2024 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MisterBrash/e7692966191bfbc46057b5464b27b44a to your computer and use it in GitHub Desktop.
Save MisterBrash/e7692966191bfbc46057b5464b27b44a to your computer and use it in GitHub Desktop.
ICS3U Lesson 1.1

1.1 - Output & the Console

ICS3U

Congratulations - yesterday we wrote the Hello World! program together!

JavaScript:

console.log("Hello World!");

The command console.log() is how we write output to the developer console. You can put words, numbers, and more inside the brackets to have them show up on the screen. For words (characters) we need to use quotation marks: console.log(" ") but for numbers we can just put the value: console.log(3.14)

We can also separate items with a comma (,) to print more than one thing! It will be separated by a space:

console.log("This","is","text.",15)    // Outputs:  This is text. 15

Special Characters & Escape Sequences

Most programming languages use some special commands for things like a new line or tab (indent). These are called escape sequences and we use a backslash \ to "escape" them.

Sequence Usage
\n Most common - used for a new line.
\r Used for a carriage return (not used often)
\t Used to insert a horizontal tab (indent)
\v Used to insert a vertical tab
\" Used to insert a single double-quote character
\' Used to insert a single single-quote character
"\" Used to insert a blackslash character

Console.log( )

Remember that you need to use quotes if you want to print text.

console.log("Line 1.\nThis is \"text\"");
/* Output:
     Line 1.
     This is "text"
*/

One last thing - every time you use the console.log( ) command, it automatically adds a new line (\n) at the end.

📝 Your Tasks:

(Read carefully and work with a partner if you are struggling - ask Mr. Brash only after asking a classmate)

  • Open VSCode.
  • Go to FILE > Close Folder (if that option exists)
  • Go to FILE > Open Folder
    • Create a new folder called "Unit 1" and select that
  • Add a new file to VSCode
    • Name the new file "1.1 - Output.js"

Now try the following coding tasks and "run" your code to test the output:

1. Add the appropriate code(s) to the JavaScript file 1.1 - Output.js that will print the address for Apple Inc.:

Apple Inc.
One Apple Park Way
Cupertino, CA
95014
+1 408-996-1010

2. Output two blank lines (to separate task 1 and 3)

3. Now print the following with only a SINGLE console.log( ) command:

Microsoft Corporation
One Microsoft Way
Redmond, WA
98052
+1 425-882-8080

4. Output two blank lines (to separate task 3 and 5)

5. Finally, output the following to the console using one console.log( ) command and horizontal tabs between the letters:

x  o  x
o  x  o
x  o  x

When you are sure that you've followed the instructions perfectly, ask Mr. Brash to check your work.

🕒 If you finish with class time left, you can complete the ISU or take a look at go.brash.ca/karel








Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment