
📎 This article includes 2 downloadable practice files ↓
In this article
“`javascript
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
- 📄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