Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT TEXT / CHAPTER 03 / Learn / LESSON 06
Sixth class. With a loop (you already know for...of) we count and search.
Counter: start at 0, increase on a match. Search: found = false; on the first match set true and break.
Mini example:
const text = "food"; let countO = 0; for (const ch of text) { if (ch === "o") countO = countO + 1; } let found = false; for (const ch of text) { if (ch === "d") { found = true; break; } } console.log(countO); console.log(found);
Common mistake: relying on a built-in count helper instead of a loop; or forgetting break after a find.
Practise with a loop, not a ready-made helper.
DATA STANDBY
›