Back

Activity 1.1 Hello World!

divider

Introduction

Activity 1.1

Hello World!

Topics

  • Output
  • User Interfaces
  • console.log()
  • Comments

Output

Output refers to information that a program produces. It can be sent to the user via some output device.

monitor
speaker
headphone

User Interfaces: GUIs and TUIs

Graphical User Interface - Uses visual elements to let you interact with a program.

GUI

User Interfaces: GUIs and TUIs

Terminal User Interface - A user interface that uses text and symbols, rather than graphical elements.

TUI

Your First JavaScript Function

console.log()

console.log() is a function that displays a message in a terminal application.

console.log("Hello world!");

Your First JavaScript Function

console.log()

console.log() is a function that displays a message in a terminal application.

console.log("Hello world!");
Sample
Hello world!

Demo: Display a message of your choice using console.log().

console.log("I love JavaScript!");
Demo
I love JavaScript!

// Comments

Comments serve two key roles: documenting code and disabling it temporarily for testing.

// This line prints a friendly greeting to the console
console.log("Hello, world!");
// console.log("This line is disabled for testing purposes.");

// Comments

Comments are completely ignored when the program is executed.

// This line prints a friendly greeting to the console
console.log("Hello, world!");
// console.log("This line is disabled for testing purposes.");
Sample
Hello, world!

Key Terms

Function
Code that performs a specific action.
Output
Information that a program produces.
Console Output
Text displayed by a program in a command-line interface, like a terminal.
Comments
Notes written within the code that are ignored by JavaScript, used by to explain or clarify the code.

'F' → Fullscreen

Objectives

  • icon Writing and executing code
  • icon Displaying console output
  • icon Debugging potential syntax errors
  • icon Reading comments
divider

Activity Tasks

  • icon Create a new JavaScript script named 1-1-output.js.
  • icon Complete each task individually.

Task 1: Write and Test

  • icon Write each line of code from the section making sure to stay within the main method.
  • icon Run and test your project to ensure it executes as intended.
1-1-output.js
console.log("Hello, world!");
console.log("This class is taught by Mr. Mortimer.");
console.log("You are currently visiting: https://skynest.nexus");
console.log(); // Display a blank line
//

Task 2: Add More Code

  • icon Write the additional sections of output under your current code.
  • icon Run and test your project to ensure it executes as intended.
1-1-output.js
console.log("Hello, world!");
console.log("This class is taught by Mr. Mortimer.");
console.log("You are currently visiting: https://sehs.io");
console.log(); // Display a blank line
console.log("What is the answer to life, the universe, and everything?");
console.log("The answer is 42.");
console.log();
console.log("Sally sells seashells by the seashore.");
console.log("Sally wants to invite you to invest in a money making opportunity.");
console.log();
console.log("If you start to feel overwhelmed, just remember:");
console.log("Mortimers don't quit, we get fired!");
console.log();
console.log();
console.log("Sincerely,");
console.log("Mr. Mortimer");
// console.log();
// console.log("Display this message for 1 extra credit point");
//

Task 3: Write a Custom Section

  • icon Output a three-line paragraph of your choice somewhere in the program. Keep it school appropriate.
  • icon Run and test your project to ensure it executes as intended.

Task 4: Comments

  • icon There is a section of code that is 'commented out'. Uncomment the code so that it executes when your program runs.
  • icon Run and test your project to ensure it executes as intended.
divider

Sample Output

Your program output should something similar to the sample output below.

Sample Output
Hello, world!
This class is taught by Mr. Mortimer.
You are currently visiting: https://skynest.nexus
What is the answer to life, the universe, and everything?
The answer is 42.
Sally sells seashells by the seashore.
Sally wants to invite you to invest in a money making opportunity.
If you start to feel overwhelmed, just remember:
Mortimers don't quit, we get fired!
Sincerely,
Mr. Mortimer
Display this message for 1 extra credit point
I also accept the following items for extra credit:
1. Expired mayonaise
2. A preserved eyeball
3. A VHS tape of a movie that nobody has heard of
divider

Reflection Questions

You may write your reflection answers as comments at the bottom of your code.

  1. What is the primary function of console.log()? How does it relate to the idea of a program "speaking" to a user?
  2. Imagine you typed Cosnol.log() by mistake. What do you think would happen when you try to run your program? Why is correct spelling so important in programming?
  3. What was the most challenging part of writing your first line of code?
divider

Submission

Submit your activity and reflection answers to the appropriate dropbox.

Activity Complete