topskill.dev
CoursesTracks
0
All courses/Introduction to JavaScriptConditionals
Control Flow
4 / 17
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Missing values and deliberate emptiness○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Comparisons and strict equality○Truthiness and combined conditions○Function inputs and results●Conditionals○Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Stop a Ticket Scan○Challenge: Number Guess Referee○Rainfall Routing Walkthrough○Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Ticket Pricing Walkthrough○Shipping Labels with Defaults○Seat Ledger Closure Walkthrough○Private Budget Ledger✦Module Quiz
○Arrays○Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Charging Rack Restock Report○Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Object copies and optional properties○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger○JSON○Throwing and catching errors○Math and Date○Date Basics○Supply Bin Audit○Volunteer Shift Audit○Workshop Attendance Feed○Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Build a Reminder with Template Literals○Format Pantry Pickup Messages○Validate a Time Slot with Regex○Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Extend the inventory report○Handle an Error-First Callback○Report Seat Reservation Results○Summarize Completed Bike Rides○Summarize Delivered Parcels✦Module Quiz
○A notebook object○OOP Introduction○Independent workshop passes○Classes○An inherited notice○Inheritance○A private seat counter○Encapsulation○Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Callback Timing○Asynchronous JavaScript○Promise Rehearsal○Promises and Async Await○Offline API Coordination○Async API Simulation○Partial Results Bulletin○Project: Resilient Awards Feed○Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

Conditionals

This section teaches a script to choose between outcomes. Keep the work in script.js and check results in the Console.

Conditional statements let your program make decisions. score >= 90 asks whether a number is at least 90 and yields true or false. In an if / else if / else chain, JavaScript checks conditions from top to bottom and runs only the first matching branch. Put the highest threshold first so 95 does not get classified by a lower one.

Syntax

javascript
if (condition) {
    // runs when condition is true
} else if (anotherCondition) {
    // runs when first was false but this is true
} else {
    // runs when none of the above matched
}

A named calculation

You just wrote a small function in the primer. Read function name(input) { ... } as a reusable calculation: the input takes a different value on each call, and return sends back its result. This separate example uses a different rule:

javascript
function accessLevel(age) {
  if (age >= 18) return "adult";
  return "minor";
}
console.log(accessLevel(20));

Use the supplied function shape to classify scores. This version returns from each matching branch, so it can use consecutive if statements without else if.

The starter supplies the function and its calls. undefined means the fallback has no finished result yet; keep it until the last task so unfinished grades can still be printed safely. Change only the indicated branch or fallback at each step.

A return ends the current function call immediately. Because every matching branch returns, these consecutive if statements behave like an if / else if chain: a score that earns A never reaches the B check. Keep them in descending order. The >= includes the cutoff itself; > would incorrectly exclude 90, 80, 70, or 60.

After completingNew completed Console line
A branchA range: A,A
B branchB range: B,B
C branchC range: C,C
D branchD range: D,D
F fallbackF range: F,F

Each earlier line should stay correct as you add the next branch. The probes include both ends of each range, not just a score in its middle.

Edit script.js, Run to inspect the supplied probes, and Submit to check the tasks.

Your Task

  1. Add the A branch for scores at least 90. The A range probe should show A,A.
  2. Add the B branch after A for scores at least 80. The B range probe should show B,B.
  3. Add the C branch after B for scores at least 70. The C range probe should show C,C.
  4. Add the D branch after C for scores at least 60. The D range probe should show D,D.
  5. Replace the fallback with a return of "F" for all remaining scores. The F range probe should show F,F.
Hint 1
1 / 3
HINT 1

Use if (score >= 90) to check for grade A.

HINT 2

Place higher cutoffs before lower ones; each matching branch returns immediately.

HINT 3

The final return handles scores below 60.

Files
  • ⋄script.js
Loading editor…
Press Run to execute your code.