Im trying to make a word finder but it shows error in the do while loop. Maybe there's a problem with the exec() function. here's my JavaScript:
const words = [/lorem/gi, /ipsum/gi];
const body = document.body;
let log = [];
for (const w of words) {
let yes = true;
let theWord = w.exec(String(body.innerHTML));
loo: do {
console.log(theWord == null);
if (theWord == null) {
yes = false;
console.log(yes);
break loo;
} else {
log.push(theWord);
}
} while (yes == true);
}
console.log(log);
i'll do the styling on the page later using index and span; but for now, please help me with this
html:
<body>
<h1>Ipsum Lorem</h1>
<h1>lorem Ipsum</h1>
<h1>Lorem ipsum</h1>
<h1>lorem ipsum</h1>
<h1>LoRem iPsUm lOrEm Lorem</h1>
<span style="display: block;">lorem ipsum</span>
<br>
<b style="display: block;">LoReM iPsUm</b>
<br>
<i style="display: block;">lOrEm IpSuM</i>
<br>
<a href="#">ipSUM LORem</a>
<br>
<br>
lorem IPSUM
<br>
<br>
<div>
LOREM ipsum
</div>
<style>
body {
background-color: #444;
color: #fff;
}
</style>
</body>
I edited the question as one asked to show the html.