Session 4

This commit is contained in:
marcgauch committed 2023-01-23 22:00:31 +01:00
1 parent 65869fbe87
commit f4babc01a9
9 files changed
+483

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
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
*/
+27
View File
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TITLE</title>
<link
href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="styles.css" />
<script src="https://unpkg.com/vue@next" defer></script>
<script src="app.js" defer></script>
</head>
<body>
<section id="app">
<p :class="paraClasses">{{ result }}</p>
{{number}}<br /><br />
<button @click="changeNumber(-10)">- 10</button>&nbsp;
<button @click="changeNumber(-5)">- 5</button>&nbsp;
<button @click="changeNumber(-1)">- 1</button>&nbsp;
<button @click="changeNumber(1)">+ 1</button>&nbsp;
<button @click="changeNumber(5)">+ 5</button>&nbsp;
<button @click="changeNumber(10)">+ 10</button>
</section>
</body>
</html>
+72
View File
@@ -0,0 +1,72 @@
* {
box-sizing: border-box;
}
html {
font-family: 'Jost', sans-serif;
}
body {
margin: 0;
}
section {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
margin: 3rem;
border-radius: 10px;
padding: 1rem;
text-align: center;
}
h2 {
font-size: 2rem;
border-bottom: 4px solid #ccc;
color: #970076;
margin: 0 0 1rem 0;
}
p {
font-size: 1.25rem;
font-weight: bold;
padding: 0.5rem;
border-radius: 25px;
}
input {
font: inherit;
border: 1px solid #ccc;
}
input:focus {
outline: none;
border-color: #1b995e;
background-color: #d7fdeb;
}
button {
font: inherit;
cursor: pointer;
border: 1px solid #ff0077;
background-color: #ff0077;
color: white;
padding: 0.05rem 1rem;
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.26);
}
button:hover,
button:active {
background-color: #ec3169;
border-color: #ec3169;
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.26);
}
.low {
background-color: #6874e1;
}
.high {
background-color: #fa2424;
}
.perfect {
background-color: #7ec932;
}