JavaScript Basics2/21

Practice: More Messages

Displaying Multiple Messages 📝

Why this matters: real programs report multiple things—status updates, debugging clues, intermediate results. Reading the console like a timeline helps you understand what your code is doing step by step.

Logging once is good, but real programs print many things: status, progress, answers, and debugging info.

Mental Model

  • Each console.log() is a new line in the console.
  • Text needs quotes; numbers do not.

You can use console.log() as many times as you want. Each one shows a new message!

Multiple Lines

console.log("Good morning!");
console.log("How are you?");
console.log("Have a great day!");

Output:

Good morning! How are you? Have a great day!

Each console.log() creates a new line.

Text vs Numbers

There's an important difference:

TypeExampleNeeds Quotes?
Text (String)"Hello"✅ Yes
Number42❌ No
console.log("My name is Alex");  // Text - needs quotes
console.log(42);                  // Number - no quotes
console.log(3.14);                // Decimal - no quotes

Why Does This Matter?

JavaScript treats text and numbers differently:

  • Text is for display, names, messages
  • Numbers are for math and calculations

Common Mistakes

console.log("42") — This is text "42", not the number 42! ✅ console.log(42) — This is the actual number 42

Your Turn!

  1. Display your name (as text, in quotes)
  2. Display your favorite number (without quotes)