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({
data() {
return {
result: 0,
counter: 0,
};
},
watch: {
result() {
status() {
const that = this;
setTimeout(function () {
that.result = 0;
that.counter = 0;
}, 5000);
},
},
computed: {
status() {
if (this.result < 37) {
if (this.counter < 37) {
return "Not there yet";
} else if (this.result > 37) {
} else if (this.counter > 37) {
return "Too much!";
} else if (this.result === 37) {
return this.result;
} else if (this.counter === 37) {
return this.counter;
}
},
},
methods: {
increaseCounter(value) {
this.result += value;
this.counter += value;
},
},
});

View File

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