
π This article includes 2 downloadable practice files β
In this article
const marks = { Aarav: 78, Diya: 91, Kabir: 45, Rohan: 33 };
for (const [name, m] of Object.entries(marks)) {
const grade = m >= 90 ? "A+" : m >= 75 ? "A" : m >= 40 ? "Pass" : "Fail";
console.log(name, m, grade);
}
Comparisons
Use === and !== (strict: same value and type). == converts types and surprises people (“0” == 0 is true). Combine with && (and), || (or), ! (not).
Loops
for (let i = 1; i <= 3; i++): counting loops.for (const x of array): each item of an array.Object.entries(obj): key-value pairs of an object.while (condition): repeat until false.
π‘ The ternary a ? b : c is great for short choices; switch to if/else blocks when it gets longer than one readable line.
Practice
Run the script and add a grade for marks above 60.
π Practice files for this article
β¬ Download all 2 files (ZIP Β· 616 B)
- πjs-03-conditions-loops.jsLesson code file.β¬ JS Β· 368 B
- πjs-03-conditions-loops-output.txtOutput from our test run.β¬ TXT Β· 98 B
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
β¨ Ask AI about this article
Stuck on a step? Ask a question and the AI answers using this article.
Free Β· AI can be wrong