correct based on the solution

This commit is contained in:
Andreas Zweili 2021-01-18 22:26:19 +01:00
parent 942a45783a
commit b562250178
2 changed files with 9 additions and 10 deletions

View File

@ -3,31 +3,31 @@
const app = Vue.createApp({ const app = Vue.createApp({
data() { data() {
return { return {
result: 0, counter: 0,
}; };
}, },
watch: { watch: {
result() { status() {
const that = this; const that = this;
setTimeout(function () { setTimeout(function () {
that.result = 0; that.counter = 0;
}, 5000); }, 5000);
}, },
}, },
computed: { computed: {
status() { status() {
if (this.result < 37) { if (this.counter < 37) {
return "Not there yet"; return "Not there yet";
} else if (this.result > 37) { } else if (this.counter > 37) {
return "Too much!"; return "Too much!";
} else if (this.result === 37) { } else if (this.counter === 37) {
return this.result; return this.counter;
} }
}, },
}, },
methods: { methods: {
increaseCounter(value) { increaseCounter(value) {
this.result += value; this.counter += value;
}, },
}, },
}); });

View File

@ -21,8 +21,7 @@
<!-- 1) Connect the buttons and calculate a value (a number) --> <!-- 1) Connect the buttons and calculate a value (a number) -->
<!-- Show "Not there yet" until you reach a result of exactly 37 --> <!-- Show "Not there yet" until you reach a result of exactly 37 -->
<!-- Show "Too much!" if the result is greater than 37 --> <!-- Show "Too much!" if the result is greater than 37 -->
<p>{{ status }}</p> <p>Result: {{ status }}</p>
<p>Result: {{ result }}</p>
<!-- 2) Watch for changes in "result" and reset the value to 0 after 5 seconds --> <!-- 2) Watch for changes in "result" and reset the value to 0 after 5 seconds -->
</section> </section>
</body> </body>