Read & Predict

Practice reading JavaScript code, predicting its output, and verifying your understanding before running the program.

~2 min read updated Jul 17, 2026 Activities
  • #teaching
  • #activity
  • #javascript
  • #functions
  • #if-statement
  • #debugging

One of the most important programming skills is being able to read code before writing code. Professional developers spend much more time reading code than typing it.

In this activity, you will analyze a JavaScript function, predict what it does, and then verify whether your prediction was correct.

Learning Objectives

By the end of this activity, you should be able to:

  • Read a JavaScript function from top to bottom.
  • Identify the purpose of an if statement.
  • Follow the flow of execution.
  • Predict a function's return value.
  • Verify your prediction by running the code.

The Big Idea

Do not run the code immediately.Good programmers first ask:

"What do I think this code will do?"

Only after making a prediction should you execute the program to check your understanding.

Code to Analyze

function calculateTotal(bill, tipPercent) {
    if (bill < 0) {
        return "Invalid bill";
    }

    let tip = bill * (tipPercent / 100);

    return bill + tip;
}

calculateTotal(100, 10);

Instructions

Read the Code

As a group, read the function from top to bottom.

Do not run it yet.

Make Your Predictions

Write your answers in your activity log before checking the result.

Answer the questions below.

Verify Your Answers

Paste the code into your editor or use an AI assistant to execute it.

Compare the actual output with your prediction.

If you were wrong, explain why.

Questions

Answer the following before running the program.

  1. What value does calculateTotal(100, 10) return?
  2. What happens if bill is -5?
  3. Which line prevents invalid bills?
  4. Identify:
    • the function
    • the if statement
    • the variable
    • the mathematical calculation

Reflection

After verifying your answers, write a short reflection.

  • Were your predictions correct?
  • What surprised you?
  • What did you learn about how JavaScript functions execute?
Don't skip the prediction step.The goal is not simply getting the correct answer. The goal is training your brain to trace code logically before relying on the computer.

Expected Output

By the end of the activity, you should have:

  • A completed prediction log.
  • Verified answers after running the code.
  • A short reflection explaining what you learned.

Submission

Submit a document containing:

  1. Your answers to the four questions.
  2. The actual output after running the program.
  3. Your reflection describing whether your prediction was correct.

Grading Rubric

CategoryPoints
Correct Predictions30
Code Identification25
Reflection & Explanation25
Participation & Completion20
Total100
Reading code is a skill that improves with practice.Every time you predict what code will do before running it, you strengthen your ability to debug programs, understand existing codebases, and write better software.

Related notes