fizzbuzz ternary operators
This commit is contained in:
parent
a724a85414
commit
fa2462cfea
|
@ -20,18 +20,28 @@
|
||||||
app.innerHTML = /*HTML*/ `
|
app.innerHTML = /*HTML*/ `
|
||||||
Input score:<input type="number" onchange="score = this.value">
|
Input score:<input type="number" onchange="score = this.value">
|
||||||
<button onclick="getScoreRating(score)">check your rating</button>
|
<button onclick="getScoreRating(score)">check your rating</button>
|
||||||
|
<button onclick="fizzBuzz()">Fizz the buzz</button>
|
||||||
<div>Your rating: ${scoreRating}</div>
|
<div>Your rating: ${scoreRating}</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//control
|
//control
|
||||||
function getScoreRating(score) {
|
function getScoreRating(score) {
|
||||||
scoreRating = score > 70 ? score + " Excellent" :
|
scoreRating = score > 90 ? score + " Excellent" :
|
||||||
|
score > 70 ? score + " Good" :
|
||||||
score > 50 ? score + " Average" :
|
score > 50 ? score + " Average" :
|
||||||
score + " Do better!";
|
score + " Do better!";
|
||||||
updateView();
|
updateView();
|
||||||
}
|
}
|
||||||
|
function fizzBuzz() {
|
||||||
|
for (let i = 1; i < 101; i++) {
|
||||||
|
let fizzbuzzOrBuzzOrFizz = i % 15 === 0 ? 'fizzbuzz' :
|
||||||
|
i % 5 === 0 ? 'buzz' :
|
||||||
|
i % 3 === 0 ? 'fizz' :
|
||||||
|
i;
|
||||||
|
app.innerHTML += `<br>${fizzbuzzOrBuzzOrFizz}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue