fizzbuzz ternary operators
This commit is contained in:
parent
5d759cb136
commit
a724a85414
38
oppgaver/uke7/ternary_operators/ternary.html
Normal file
38
oppgaver/uke7/ternary_operators/ternary.html
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script>
|
||||||
|
// model
|
||||||
|
var app = document.getElementById('app');
|
||||||
|
var score;
|
||||||
|
var scoreRating = '';
|
||||||
|
//view
|
||||||
|
updateView();
|
||||||
|
function updateView() {
|
||||||
|
app.innerHTML = /*HTML*/ `
|
||||||
|
Input score:<input type="number" onchange="score = this.value">
|
||||||
|
<button onclick="getScoreRating(score)">check your rating</button>
|
||||||
|
<div>Your rating: ${scoreRating}</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//control
|
||||||
|
function getScoreRating(score) {
|
||||||
|
scoreRating = score > 70 ? score + " Excellent" :
|
||||||
|
score > 50 ? score + " Average" :
|
||||||
|
score + " Do better!";
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in a new issue