noknow.dev
Sign inSign up
Course overview
JavaScript Fundamentals
0 / 7 lessons0%

Getting Started

  • Hello, World!
  • Variables: let and const
  • Numbers and Math

Decisions & Loops

  • if / else — Making Decisions
  • for Loops

Functions

  • Defining Functions
  • Arrow Functions

if / else — Making Decisions

0m 00s

Code that decides

Often your program needs to behave differently depending on a condition. That's what if and else are for:

const temperature = 22

if (temperature > 30) {
  console.log("It's hot!")
} else if (temperature > 15) {
  console.log("Nice weather")
} else {
  console.log("Put on a jacket")
}
// Output: Nice weather

Comparison operators

5 > 3    // true  — greater than
5 < 3    // false — less than
5 >= 5   // true  — greater than or equal
5 === 5  // true  — strictly equal (always use === not ==)
5 !== 3  // true  — not equal

Your task

Write a function grade(score) that returns a letter grade:

  • 90 or above → "A"
  • 70 to 89 → "B"
  • 50 to 69 → "C"
  • below 50 → "F"
Back
javascriptCtrl+Enter to run
Output

Click "Run" to execute your code.