completefrontend
Open lab My progress
THE JAVASCRIPT FIELD GUIDE

Thinking like a developer

Learn the developer habit of restating a problem, planning with pseudocode, building small functions, and testing assumptions before trusting your code.

By the end, you'll be able to
  • 01
    Say a problem clearly in your own wordsName what goes in, what comes out, one example, and the rules, before you write code.
  • 02
    Turn a plan into small functionsWrite the steps in plain words, then make each step one small function you can test.
  • 03
    Test your guesses earlyTry normal inputs and unusual inputs, so surprises show up while the code is still small.

The developer habit

New developers often ask, "What code do I write?" Experienced developers ask a different question first: what problem am I solving? Asking this first saves time. Without it, you may write ten lines, find out the goal was different, and delete them all.

In this lesson you solve one small problem from start to finish: split a restaurant bill, with a tip, between friends. The program gets three numbers:

  • the bill amount,
  • the tip percent,
  • the number of people.

It gives back one number: how much each person pays, rounded to two decimal places. For rupees, two decimal places means paise (100 paise make 1 rupee). You will do four things, in this order:

  1. Say the problem again in your own words.
  2. Write a plan in plain words.
  3. Turn the plan into small functions.
  4. Test your guesses with real JavaScript.
The short version

Thinking like a developer means you make an unclear request clear before you trust any code. You name what goes in, what comes out, the steps, and the checks.

One answer worked out firstPop out in the code editor (opens in a new tab)JavaScript
const people = 4;const total = 96;const eachPays = total / people;console.log(eachPays);

Line 1 stores the number of people, 4. Line 2 stores the total after the tip, 96. Line 3 divides the total by the number of people. Line 4 prints 24. This is a known answer. Later, you can compare the full program with it.

A tip of zero is allowedPop out in the code editor (opens in a new tab)JavaScript
const bill = 12;const tipPercent = 0;const total = bill + (bill * tipPercent) / 100;console.log(total);

Line 1 stores a bill of 12. Line 2 sets the tip percent to 0. A zero tip is allowed. Line 3 adds the tip, but the tip is zero, so the total stays the same. Line 4 prints 12.

So zero is not always a problem. A tip of 0% is fine. A count of 0 people is not, because you can't split a bill between nobody. A good rule says exactly which values are allowed.

Real-life analogyA shopping list before the shop

Before you go shopping, you check three things. What do you need? What is already at home? How much can you spend? Then you write a list. A coding request needs the same quick check before you choose the steps.

In real life: What you need to buy
In JavaScript: The output: the answer you need
In real life: Food already in the kitchen
In JavaScript: The inputs: what you already have
In real life: How much money you can spend
In JavaScript: A rule the answer must follow
In real life: The shopping list
In JavaScript: A short plan before you start

This is the last lesson in Stage 1. You have already seen first programs, the console, code structure, strict mode, the browser, code style, linting, and debugging. Stage 2 starts with variables.

This lesson uses a few small functions and if checks. Each one is explained when it first appears. Full lessons on functions and if come later.

Understanding the problem

SORT

The first job is not to write JavaScript. The first job is to say the request again in plain words that you can check. This is called a restatement. A good restatement names four things:

  • Inputs: the values the code gets.
  • Output: the answer the code gives back.
  • Examples: real numbers you work out by hand.
  • Constraints: rules the answer must follow, such as "at least one person".
Work out the tipPop out in the code editor (opens in a new tab)JavaScript
const bill = 80;const tip = bill * 0.2;const total = bill + tip;console.log(total);

Line 1 stores the bill, 80. Line 2 works out a 20% tip. 20% is the same as 0.2, so the tip is 16. Line 3 adds the tip to the bill. Line 4 prints 96. You can use this small answer to check the bigger program later.

The bill problem in plain wordsText
// Problem statement// Given a bill amount, tip percent, and number of people,// return how much each person pays, rounded to two decimal places. // Example: bill 80, tip 20%, people 4 -> 24

Line 2 names the inputs. Line 3 names the output and the rounding rule. Line 5 is one example worked by hand.

Three input cards, bill 80, tip 20%, and people 4, have arrows into a function card called calculateShare. An arrow from it leads to the output card, 24. Underneath: the rules are at least 1 person and round to 2 places.inputsbill: 80tip: 20%people: 4the jobcalculateShareoutput24rules: at least 1 person, round to 2 places
Before any code, name the three things the program gets (the inputs), the one answer it gives back (the output), and the rules the answer must follow.

Work one example by hand before you write code:

  1. The bill is 80.
  2. A 20% tip adds 16, so the total is 96.
  3. Four people share it, so each person pays 24.

This example is your first check. If your code gives 20, you forgot the tip. If it gives 96, you forgot to divide. If it gives 2400, the rounding step forgot to divide by 100 at the end.

Be just as exact about the output. "Show the total" can mean three different things:

  • print a value in the console, so you can check it;
  • return a value, so another part of the program can use it;
  • put text on the page, so the person using the site can read it.

Write down which one the task needs.

Input, output, or constraint?
  • The bill amount, such as 80
  • The tip percent, such as 20
  • The number of people sharing the bill
  • The amount each person pays
  • Print or return 24 for the example worked out by hand
  • Round the answer to two decimal places
  • There must be at least one person
Try it yourself
0 of 7 correct

Sort each part of the bill problem into Input, Output, or Constraint.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Asking questions about the task is part of the work. Good questions for the bill problem:

  • Can the bill be negative?
  • Can the tip be negative?
  • What should happen with zero people?
  • Do we round each person's share, or the whole bill?

Sometimes nobody knows the answer yet. Then make your best guess and write it down. A guess you have not checked yet is called an assumption. Later, you test it.

Pseudocode: a plan in plain words

INTERACTIVE

Pseudocode is a plan written in ordinary words. It is not JavaScript, so the browser can't run it. That is on purpose. You think only about the order of the steps. You don't worry about commas, brackets, or exact names yet.

Real-life analogyPseudocode is a first draft of a recipe

Before you cook a new dish, you might jot down the steps: chop the vegetables, heat the pan, add the sauce, taste. You don't measure every gram yet. You only check that the steps make sense in that order.

In real life: List the ingredients
In JavaScript: Name the inputs
In real life: Write the cooking steps
In JavaScript: Write the steps in plain words
In real life: Taste and adjust
In JavaScript: Test your guesses and the unusual inputs
The bill plan in plain wordsPseudocode
Start with the bill amount, tip percent, and number of people.Check that the number of people is more than 0.Add the tip to get the total.Divide the total by the number of people.Round the answer to two decimal places.Return the amount each person pays.

Line 1 names the three inputs. Line 2 is a check: there must be at least one person. Lines 3, 4, and 5 are the steps. Line 6 says what comes out.

The order matters:

  • You can't split the bill until the total includes the tip.
  • You should round only after you divide. If you round first and then divide, the answer can have long decimals again. For example, 10 divided by 3 is 3.3333…

Keep each step small enough to check. "Work out the bill" hides the real choices. "Add the tip, divide by people, then round" gives each later line of code one clear job. If the task says "handle bad input", write the exact rule, such as "stop when people is zero or less".

Now put the plan back in order below. Each step has two buttons, Move up and Move down.

Put the plan in order
The plan in plain wordsPseudocode
Start with the bill amount, tip percent, and number of people.Check that the number of people is more than 0.Add the tip to get the total.Divide the total by the number of people.Round the answer to two decimal places.Return the amount each person pays.
Mixed-up stepskeep going
  1. Divide the total by the number of people.
  2. Say the goal: the amount each person pays, rounded to two decimal places.
  3. Try normal inputs and unusual inputs.
  4. Add the tip to get the total.
  5. Round the answer to two decimal places.
  6. Work out one example by hand: 80 + 20% = 96, then 96 / 4 = 24.
Try it yourself
1 of 6 in the right place

Work out one example by hand before the math steps. It gives you numbers to compare with.

Use the Move up and Move down buttons to reorder the plan. The message below tells you when a step comes before a step it needs, like splitting before the tip is added.

If you get stuck, explain the plan out loud to a friend. When you say "then I divide by people", you may notice a missing check: what if people is 0?

Small functions have one job

STEP THROUGH

Now turn the plan into JavaScript. You will use functions. A function is a group of lines with a name:

  • You give it some values, called its inputs.
  • It runs its lines.
  • It hands an answer back with the word return.

A small function does one job, such as "add a tip" or "round a number". When each part is simple, the whole program is easier to test and to fix.

One small functionPop out in the code editor (opens in a new tab)JavaScript
function addTip(bill, tipPercent) {  return bill + (bill * tipPercent) / 100;}console.log(addTip(50, 20));

Line 1 makes a function called addTip. It has two inputs, bill and tipPercent. Line 2 works out the tip as (bill * tipPercent) / 100, adds it to the bill, and returns the result. Line 4 calls the function with 50 and 20. The tip is 10, so the console prints 60.

A function hands back a value; printing is a separate stepPop out in the code editor (opens in a new tab)JavaScript
function addTip(bill, tipPercent) {  return bill + (bill * tipPercent) / 100;} const total = addTip(80, 0);console.log(total);

Line 2 returns the answer to the line that called the function. It does not print anything. Line 5 calls addTip(80, 0) and keeps the answer in total. Line 6 prints 80. This call is also a quick test: with a 0% tip, the bill should not change.

The full program has three small functions. Each one matches one line of the plan. A small function that another function calls is often called a helper.

Three plan cards on the left, add the tip, divide by people, and round to 2 places, each have an arrow to one function card on the right: addTip, splitBill, and roundCurrency.plan in plain wordssmall functionadd the tipaddTipdivide by peoplesplitBillround to 2 placesroundCurrency
Each line of the plan turns into one small function with one job. The answer from each function is passed to the next one, in the same order as the plan.
The plan as small functionsPop out in the code editor (opens in a new tab)JavaScript
function addTip(bill, tipPercent) {  return bill + (bill * tipPercent) / 100;} function splitBill(total, people) {  return total / people;} function roundCurrency(amount) {  return Math.round(amount * 100) / 100;} function calculateShare(bill, tipPercent, people) {  const totalWithTip = addTip(bill, tipPercent);  const each = splitBill(totalWithTip, people);  return roundCurrency(each);} console.log(calculateShare(80, 20, 4));

Here is what each part does:

  • Lines 1 to 3: addTip returns the bill plus the tip.
  • Lines 5 to 7: splitBill divides a total by the number of people.
  • Lines 9 to 11: roundCurrency rounds to two decimal places. Math.round rounds a number to the nearest whole number. So the function first multiplies by 100, then rounds, then divides by 100 again.
  • Lines 13 to 17: calculateShare is the main function. It calls the three helpers in the same order as the plan.
  • Line 19 calls calculateShare(80, 20, 4) and prints 24.

Now step through the same code below, one step at a time. The "Running in" label shows which function is running at each step. This is a replay that was recorded from the real functions, so every value you see is real. It is not a full browser debugger.

Step through the helper functions
Step 0 of 12Ready
Your turn: follow the blue line

Guess how much each person pays. Then step through the helper calls and watch each step of the plan give a real value.

Running in
  1. script
Next: line 19
function addTip(bill, tipPercent) {  return bill + (bill * tipPercent) / 100;} function splitBill(total, people) {  return total / people;} function roundCurrency(amount) {  return Math.round(amount * 100) / 100;} function calculateShare(bill, tipPercent, people) {  const totalWithTip = addTip(bill, tipPercent);  const each = splitBill(totalWithTip, people);  return roundCurrency(each);} 
CallStoreChangeResultBlue line: runs next. Ran: already executed.
Recent returnsNothing yet. Start with the blue line.
Choose the inputs for line 19

When you change the inputs, the replay starts again. Try the zero-people inputs after the normal ones.

A guided replay recorded from real JavaScript calls, not an engine debugger. Step follows executed statements; Back reviews a snapshot. Reset starts a fresh run.
Make it work, then make it right

First, make a tiny version work for the normal example. Then make it right: choose better names, split out helpers, add checks, and test the unusual inputs. "Make it work" does not mean you can ignore bugs. It means you start from a small version that works, and improve it from there.

Small does not mean one function for every tiny calculation. Make a helper when at least one of these is true:

  • it has a clear name;
  • you want to test it on its own;
  • it makes the main function easier to read.

addTip, splitBill, and roundCurrency pass this test. A helper named doStep would not. Its name doesn't say what job it does.

Testing your assumptions

INTERACTIVE

An assumption is a guess you have not checked. Assumptions can hide bugs. The first bill program guesses three things:

  • people is a whole number bigger than 0.
  • The tip is not negative.
  • Rounding to two decimal places is enough.

When one of these guesses is wrong, JavaScript often does not complain. It may give you a value like Infinity and carry on.

Check while the code is small

Before you use a function on a real page, test it with a few inputs: a normal one, a small one, a large one, and an unusual one. A test runs the code with one input and compares the answer with the answer you expect. An unusual input at the edge of what is allowed, such as 0 people, is called an edge case.

Dividing by zero gives InfinityPop out in the code editor (opens in a new tab)JavaScript
console.log(90 / 0);

This one line prints Infinity. JavaScript allows the division and gives no error. But Infinity makes no sense as a share of a bill. So the program needs a rule that runs before it divides.

Check whether a people count is wholePop out in the code editor (opens in a new tab)JavaScript
console.log(Number.isInteger(3));console.log(Number.isInteger(1.5));

Number.isInteger asks one question: is this number whole, with no part after the decimal point? Line 1 prints true for 3. Line 2 prints false for 1.5. You can split a bill between three people, but not between one and a half people. So the check needs two rules: more than zero, and a whole number.

Checks that run before the mathPop out in the code editor (opens in a new tab)JavaScript
function calculateShareGuarded(bill, tipPercent, people) {  if (people <= 0) return "Add at least one person";  if (!Number.isInteger(people)) return "People must be a whole number";  if (bill < 0) return "Bill must be zero or more";  if (tipPercent < 0) return "Tip cannot be negative";   const totalWithTip = addTip(bill, tipPercent);  const each = splitBill(totalWithTip, people);  return roundCurrency(each);}

Lines 2 to 5 are checks. Each one uses if. An if asks a yes-or-no question. When the answer is yes, the rest of that line runs. Here, the rest of the line is return with a clear message, so the function stops early and hands back the message.

A check like this, at the top of a function, is called a guard clause, or just a guard. It checks one rule and stops the function when the rule is broken. Line 3 uses !, which means "not": "if people is not a whole number". Lines 7 to 9 do the normal math only after every check passes. You will learn if fully in Stage 2.

Left, no guard: people = 0 is divided and gives Infinity, which is wrong for a bill. Right, with a guard: people = 0 is checked first and gives the message Add at least one person, which is a clear answer.no guardpeople = 0divideInfinitywrong for a billwith a guardpeople = 0check firstAdd at least one personclear message
Both sides get 0 people. Without a guard, JavaScript divides anyway and gives Infinity. With a guard, the function checks first and returns a clear message instead.

Try it below. Turn each case on or off, and compare the answers. The "No checks" column is the first program, with no guards. The "With checks" column is the program with guards.

Compare the answers with and without checks
The function with checksPop out in the code editor (opens in a new tab)JavaScript
function calculateShareGuarded(bill, tipPercent, people) {  if (people <= 0) return "Add at least one person";  if (!Number.isInteger(people)) return "People must be a whole number";  if (bill < 0) return "Bill must be zero or more";  if (tipPercent < 0) return "Tip cannot be negative";   const totalWithTip = addTip(bill, tipPercent);  const each = splitBill(totalWithTip, people);  return roundCurrency(each);}
Real answers2 cases
CaseAnswer you expectNo checksWith checks
Normal dinner242424
Three ways, needs rounding3.333.333.33
Try it yourself

The No checks column is the first program. It shows what JavaScript really gives back. The With checks column is the program with guards. It tests each rule before it does the math.

Turn each case on or off. Infinity is not a JavaScript error, and neither is the answer for a negative tip. Both are still wrong answers for splitting a bill.

Now step through the guarded function itself. It starts with zero people. Switch to a normal bill or a negative tip, and see which check stops the function.

Step through the input checks
Step 0 of 4Ready
Your turn: follow the blue line

Step through the checks. An input that breaks a rule returns a message early. Good inputs reach the math.

Running in
  1. script
Next: line 24
function addTip(bill, tipPercent) {  return bill + (bill * tipPercent) / 100;} function splitBill(total, people) {  return total / people;} function roundCurrency(amount) {  return Math.round(amount * 100) / 100;} function calculateShareGuarded(bill, tipPercent, people) {  if (people <= 0) return "Add at least one person";  if (!Number.isInteger(people)) return "People must be a whole number";  if (bill < 0) return "Bill must be zero or more";  if (tipPercent < 0) return "Tip cannot be negative";   const totalWithTip = addTip(bill, tipPercent);  const each = splitBill(totalWithTip, people);  return roundCurrency(each);} 
CallStoreChangeResultBlue line: runs next. Ran: already executed.
Recent returnsNothing yet. Start with the blue line.
Choose the inputs for the function with checks

When you change the inputs, the replay starts again. Compare a normal bill with an unusual one.

A guided replay recorded from real JavaScript calls, not an engine debugger. Step follows executed statements; Back reviews a snapshot. Reset starts a fresh run.

So there are two different kinds of problem:

  • A JavaScript error: the language can't run the code, and stops with a message.
  • A wrong answer for the task: the code runs fine, but the result makes no sense for your problem.

90 / 0 is valid JavaScript and gives Infinity. It is still the wrong answer to "split this bill". Tests catch this second kind of problem.

Rounding each share can also leave a small amount left over. When 10 is split three ways, each share is 3.33. Three shares of 3.33 add up to 9.99, not 10. A real checkout needs a clear rule for that last paisa.

JavaScript also stores many decimal numbers only roughly. For example, this function rounds 1.005 to 1, not 1.01. So this function is fine for learning, but not for real payments. A real payment system usually counts money in whole paise, so it never needs decimals, and it follows a written rounding rule.

Where you'll use this

You will use these steps in almost all front-end work. Before you write code for a form, say what the form needs: the inputs, the output, the rules, and one example. Before you fix a bug, write down three things:

  • what you expected to happen;
  • what actually happened;
  • the smallest step that could explain the difference.
A tiny cart totalPop out in the code editor (opens in a new tab)JavaScript
function cartTotal(price, quantity) {  if (quantity <= 0) return "Choose at least one item";  return price * quantity;}console.log(cartTotal(3, 2));

Line 1 makes a function called cartTotal. It has two inputs, price and quantity. Line 2 is a guard: the quantity must be at least one. Line 3 multiplies the price by the quantity. Line 5 tries a price of 3 and a quantity of 2, so it prints 6.

Test a normal quantity and quantity 0Pop out in the code editor (opens in a new tab)JavaScript
function cartTotal(price, quantity) {  if (quantity <= 0) return "Choose at least one item";  return price * quantity;} console.log(cartTotal(3, 2));console.log(cartTotal(3, 0));

Line 6 prints 6. Line 7 asks for 0 items, so the guard on line 2 stops the function. It prints Choose at least one item.

A boundary case is a value right at the edge of a rule. Here the rule is "at least one item", and 0 is right at its edge. Always test a normal case and a boundary case together. Each one catches a different mistake.

Give a form a clear answerPop out in the code editor (opens in a new tab)JavaScript
function nameMessage(name) {  if (name.trim() === "") return "Enter your name";  return "Welcome, " + name;} console.log(nameMessage("Asha"));console.log(nameMessage(""));

Line 2 uses trim(). It removes spaces from the start and the end of a piece of text. If nothing is left, the name is empty, and the function returns Enter your name. Otherwise line 3 returns a welcome. Line 6 prints Welcome, Asha. Line 7 prints Enter your name. This is the same pattern as the cart: name the rule, check it first, then return the normal answer.

Turn a typed quantity into a number before doing mathPop out in the code editor (opens in a new tab)JavaScript
const typedQuantity = "3";const quantity = Number(typedQuantity);console.log(quantity + 1);

A form box on a web page always gives you text, even when the person typed a number. Line 1 stands for that text, "3". Line 2 uses Number() to turn the text into the number 3. Line 3 prints 4. Without line 2, "3" + 1 would join the two as text and give "31".

So turn form values into numbers, and check them, as soon as you read them. Programs that run outside the browser, in Node, get their input in other ways. They still need clear rules for it.

The table below shows the same steps in four everyday situations. Read each row from left to right: what happens, what to ask, and what to try first.

Problem-solving steps in everyday JavaScript
When this happensWhat should you ask?What should you try first?
A button should open a menu.What changes when someone clicks the button?Give that change a name, and print it before you change the page.
A form says good input is wrong.Which rule is failing?Try one input and print the result of each rule.
A total is wrong by one paisa.Where exactly does the code round?Work out one example by hand and compare each step.
Someone reports that a page is broken.What exact input did they use, and what did they see?Ask for the steps to repeat it, then shrink it to a tiny example.

You can use these steps together with the earlier lessons. Read the code from top to bottom, as in Code structure. Print values in the browser console. When the code gets bigger, use the browser debugger to check one assumption at a time.

Common misconceptions

"Real developers know the code right away."

Experienced developers spend a lot of time asking questions, working out examples, and deleting first tries. Thinking before typing is part of the job.

"Pseudocode is a waste of time because it doesn't run."

Not running is what makes it useful. You can fix the plan while changes are quick and easy, before commas and brackets hide a bigger mistake.

"One big function is simpler."

It can feel simpler at first, but it is harder to test. With small functions, you can ask "Does adding the tip work?" without running the whole program.

"If JavaScript shows no error, the answer is right."

JavaScript can give Infinity, NaN (which means "not a number"), or a number rounded in a surprising way, all without an error. You still have to check that the answer makes sense for your problem.

"Tests are only for finished code."

Tiny tests help while you are still thinking. An example worked out by hand, and one line printed in the console, can guide the next line you write.

A restatement, pseudocode, and JavaScript each answer a different question. Read each row as: "this thing answers this question, like this."

Restatement, pseudocode, and JavaScript
What you writeWhat question does it answer?Example from the bill
RestatementWhat are we solving?Split a bill with a tip and find what each person pays.
PseudocodeWhat are the steps, in order?Add the tip, divide by people, then round.
JavaScriptHow exactly does the computer do each step?return Math.round(amount * 100) / 100;

Practice: plan before you type

6 EXERCISES
Exercise 1 · Warm-upWrite pseudocode for a snack order

A shop sells one kind of snack. The program gets three inputs: the price of one snack, the quantity, and the tax percent. It gives back the total price. Write the plan in plain words before you write any code.

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · PracticeImplement one small function

    Paste the starter code into your console or editor. It prints the answer of addTip(50, 20). Type the number it should print.

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    function addTip(bill, tipPercent) {
      return bill + (bill * tipPercent) / 100;
    }
    console.log(addTip(50, 20));

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeFind the input nobody checked

      Predict what this code really prints. Don't answer what the function should do. Answer what JavaScript actually prints, since this function has no guard.

      Starter codePop out in the code editor (opens in a new tab)JavaScript
      function splitBill(total, people) {
        return total / people;
      }
      console.log(splitBill(90, 0));

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeWrite three test cases

        Write three tests you would run before you trust the bill program. For each one, write the inputs and the answer you expect.

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeRound to two decimal places

          The answer should be rounded to two decimal places, not to whole rupees. What does this program print?

          Starter codePop out in the code editor (opens in a new tab)JavaScript
          function roundCurrency(amount) {
            return Math.round(amount * 100) / 100;
          }
          console.log(roundCurrency(10 / 3));

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeProtect a shopping cart quantity

            A shopping page lets someone pick a price and a quantity. The total is the price times the quantity, but the quantity must be at least one. Finish the function. Then type what it should return for cartTotal(3, 0).

            Starter codePop out in the code editor (opens in a new tab)JavaScript
            function cartTotal(price, quantity) {
              // Add a quantity check and return the total.
            }
            console.log(cartTotal(3, 0));

            Answer, then press Check. Spacing and letter case don’t matter.

              Quiz: check your understanding

              7 QUESTIONS

              Each answer comes with a short reason. If you miss one, read the reason. Then ask which step it is about: the inputs, the output, the plan, or a guess you should test.

              Lesson quiz · 7 questionsScore: first tries count
              1. Question 1 of 7A coding task is unclear. What should you do first?

                Choose an answer to see the explanation.

              2. Question 2 of 7In the bill example, which one is the output?

                Choose an answer to see the explanation.

              3. Question 3 of 7What does this program print?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                function splitBill(total, people) {
                  return total / people;
                }
                console.log(splitBill(90, 0));

                Choose an answer to see the explanation.

              4. Question 4 of 7Why write pseudocode before JavaScript?

                Choose an answer to see the explanation.

              5. Question 5 of 7What does the rounding program print?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                function roundCurrency(amount) {
                  return Math.round(amount * 100) / 100;
                }
                console.log(roundCurrency(10 / 3));

                Choose an answer to see the explanation.

              6. Question 6 of 7Which function has the smallest job?

                Choose an answer to see the explanation.

              7. Question 7 of 7Which guess should you test before you trust the first bill program?

                Choose an answer to see the explanation.

              Key takeaways

              • Before you code, say the problem in your own words: the inputs, the output, an example, and the rules.
              • Pseudocode is a plan in plain words. It lets you think about the steps without JavaScript details.
              • Small functions are easier to name, test, fix, and use again.
              • Test normal inputs and unusual inputs. Code can run with no error and still give a wrong answer.
              • Saying the plan out loud, and working out one example by hand, show missing steps quickly.

              Remember the one-liner.
              A developer turns "make it work" into a clear goal, a small plan, and tests that show the answer is right.

              Coming next: Variables: let, const & var.

              CompleteFrontend Clear concepts. Working examples.