software-development-2022-e.../session-4/3-number-guesser/app.js

91 lines
1.9 KiB
JavaScript

const app = Vue.createApp({
data() {
return {
target: Math.ceil(Math.random() * 101) - 1,
number: 0,
};
},
methods: {
changeNumber(num) {
this.number += num;
// erlaubt keine nummern kleiner als 0 oder grösser als 100
if (this.number < 0) {
this.number = 0;
} else if (this.number > 100) {
this.number = 100;
}
},
},
computed: {
result() {
if (this.number === this.target) {
return "Nice";
} else if (this.number < this.target) {
return "too low";
} else {
return "too high";
}
},
paraClasses() {
return {
low: this.number < this.target,
perfect: this.number === this.target,
high: this.number > this.target,
};
},
},
});
app.mount("#app");
/*
this.something = true //setzen auf true
!this.something // NOT true. ändert aber nichts da wir es nicht zuweisen
this.something = !this.something // zuerst rechts vom = NOT True. also wird FALSe zugewiesen
this.something // ist jetzt false
----
another = true
another != another -> Das ist KEINE zuweisung sondern ein Vergleich.
TRUE != TRUE -> das ist false weil TRUE ist nicht ungleich TRUE
---
const a = 3
const b = 4
const c = a + b + b
const d = a + 2 * b
console.log(c) // gibt 11 aus
console.log(d) // gibt 11 aus
----
Unterschied =, == und ===
// = weist dem ausdruck links das von rechts zu
// == vergleicht
// === vergleicht ebenfalls (aber strenger. es wird auf den Datentyp geachtet)
const a = "1"
const b = 1
const c = true
console.log(a == b) // true
console.log(a === b) // false. Weil der Datentyp ist nicht gleich. String und Nummer
console.log(a == c) // true
console.log(c == a) // true
console.log(a === c) // false. String und boolean
console.log(b == c) // true
console.log(b === c) // false. Nummer und boolean
*/