Olympics Coding Instroduction
 
🏀 Code the Olympics - Starter Code

🏀 Olympics Basketball Winners 🏀

Starter Code - JavaScript Variable Practice

📋 Instructions: Open your CodeHS assignment to complete this activity. You'll be working in the CodeHS coding platform where you can write, test, and run your JavaScript code.

🔗 Assignment Link: Click here to open your CodeHS assignment

🤔 Why Do Programmers Do This?

Declaring Variables:

Variables are like labeled containers that store information. Instead of typing "United States of America" multiple times throughout your code, you declare it once as a variable (like country1) and reuse it whenever needed. This makes your code more efficient, easier to update, and less prone to typos. If you need to change the country name later, you only update it in one place!

Printing to the Screen:

console.log() is how programmers display information to users or check if their code is working correctly. Think of it as the "announcement system" for your program - it shows results, debug information, or messages. In this project, you'll use it to announce the Olympic medal winners to anyone viewing your program's output!

💬 JavaScript Vocabulary: Statements vs. Commands

In JavaScript, we use the term "statements" rather than "commands."

What is a statement?
A statement is a unit of code that performs an action. It's the formal term used in JavaScript documentation and the official JavaScript specification. Each line of code that does something is a statement.

Examples in your code:
let country1 = "United States of America"; ☝️ This is a variable declaration statement

console.log("Gold: " + country1); ☝️ This is a function call statement

📚 For CodeHS and this course: Use the term "statements" when discussing JavaScript code. This is the correct professional terminology and what you'll see in all JavaScript resources and documentation. While "commands" is common in everyday language, "statements" is the precise term for JavaScript programming.

🔑 Let vs. Const: What's the Difference?

let - Use this when the value might change later in your program. It's flexible and allows reassignment.
let score = 10; // Can change to score = 20 later

const - Use this when the value should NEVER change. It's a constant that's locked in place.
const PI = 3.14159; // Cannot change this value

💡 For today's lesson: We use let to give you flexibility as you learn. In the future, you'll choose between let and const based on whether your data needs to change or stay constant!

⚙️ What is the main() Function?

The main() function is the "starting point" of your program - it's where your code begins executing. Think of it like the "Play" button on a video game or the ignition in a car.

How it works:
1️⃣ You write all your statements INSIDE the main() function (between the curly braces {})
2️⃣ At the end, you "call" or "invoke" the function by writing main();
3️⃣ This tells JavaScript: "Execute all the statements inside main now!"

🎯 Think of it like: Writing a recipe (the function) versus actually cooking the meal (calling the function). The recipe exists, but nothing happens until you follow it!

🌍 Variables Work the Same in ALL Programming Languages!

Whether you're coding in JavaScript, Python, Java, C++, or any other language, the concept of variables remains the same:

Declare - Tell the computer you want to store information
Initialize - Give that information an initial value
Reuse - Reference that stored information throughout your program

📚 Same concept, different syntax:
JavaScript: let name = "USA"; Python: name = "USA" Java: String name = "USA"; C++: string name = "USA";

🚀 The Big Picture: Once you understand variables in JavaScript, you've learned a fundamental concept that transfers to EVERY programming language you'll ever use. The words might change, but the idea stays the same!

💻 Your Starter Code (Already in CodeHS)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function main() { // Declare and initialize variables // Print men winners // Print women winners } main();

💡 Remember:

  • Use let to declare your four country variables
  • Use console.log() to print your results
  • Use the + operator to concatenate strings and variables
  • Reuse variables when the same country wins multiple medals!
  • Add console.log(); for blank lines between sections
Last updated  2025/12/16 05:43:18 PSTHits  68