This commit is contained in:
Philippe Torrel
2026-09-16 10:38:23 +02:00
parent 99007ffc89
commit dc1e06ac67
16 changed files with 159 additions and 27 deletions
+34 -4
View File
@@ -33,11 +33,41 @@
<script>
'use strict';
// const username = prompt('Wilkommen. Wie heißen Sie?');
const QUESTION_1 = 'Which Operators has the higher priority: * or + ?';
const SOLUTION_1 = '*';
/*
TODO: Your Code
*/
const QUESTION_2 = "What's the German word for if";
const SOLUTION_2A = 'wenn';
const SOLUTION_2B = 'falls';
// 1.Als ersten Schritt fragen Sie den Spieler nach seinem Namen, speichern diesen in eine Variable und begrüßen ihn mittels einer Alert-Box.
const name = prompt('Wie heißen Sie?');
alert(`Hallo ${name}`);
// 2.Stellen Sie dem Spieler die Frage, ob er sich fit genug fühlt, um gegen das dunkle JavaScript anzutreten. Es ist sinnvoll, bei der Frage die Antwortmöglichkeiten anzugeben.
const fitness = prompt('Fühlen Sie sich fit genug, um gegen das dunkle JavaScript anzutreten. ja oder nein?');
if (fitness === 'ja') {
alert('Das Spiel startet! Gib alles !');
let answer = prompt(QUESTION_1);
if (answer === SOLUTION_1) {
alert('Gratulation');
let answer = prompt(QUESTION_2);
if (answer === SOLUTION_2A || answer === SOLUTION_2B) {
alert('Gratulation');
let answer = prompt('Now, please enter a string with a length between 8 and 15 characters…');
if (answer.length >= 8 && answer.length <= 15) {
alert('Gratulation');
} else {
alert('Das war falsch!');
}
} else {
alert('Das war falsch!');
}
} else {
alert('Das war falsch!');
}
} else if (fitness === 'nein') {
alert('Go Home');
}
</script>
</body>
</html>
@@ -34,10 +34,32 @@
// Aufgabe
const firstName = prompt('Wilkommen. Wie heißen Sie mit Vornamen?');
const lastName = prompt('Und mit Nachnamen?');
const age = Number(prompt('Wie alt sind Sie?'));
const favoriteHotDrink = prompt('Und was ist ihr liebstes Heißgetränk? tee (t) oder kaffee (c)?');
const age = Number('Wie alt sind Sie?');
let errorMessage = '';
const favoriteHotDrink = prompt('Und was ist ihr liebstes Heißgetränk? (tee | kaffee)');
if (lastName.length < 2 || lastName.length > 100) {
errorMessage += 'name ';
}
if (firstName.length < 2 || firstName.length > 100) {
errorMessage += 'first name ';
}
if (favoriteHotDrink !== 'c' && favoriteHotDrink !== 't') {
errorMessage += 'favoriteHotDrink ';
}
if (isNaN(age) || age >= 150) {
errorMessage += 'age ';
}
if (errorMessage === '') {
console.log('OK!');
} else {
console.log(`KO! The following entries are invalid: ${errorMessage}`);
}
</script>
</body>
</html>
+12 -1
View File
@@ -45,10 +45,21 @@
const inputEl = document.querySelector('.input-year');
const outputEl = document.querySelector('.output');
const isLeapYear = (year) => {
const checkOne = year % 400 === 0;
const checkTwo = year % 100 !== 0 && year % 4 === 0;
return checkOne || checkTwo;
};
let output = '';
inputEl.addEventListener('input', (e) => {
const val = e.currentTarget.value;
// TODO: check if it is a leap year or not.
output = isLeapYear(val) ? `${val} ist ein Schaltjahr` : `${val} ist KEIN Schaltjahr`;
console.log(output);
outputEl.textContent = output;
});
</script>
</body>
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -41,6 +41,8 @@
const text =
'Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen Nadel Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen Heuhaufen';
outputEl.textContent = text.indexOf('Nadel');
</script>
</body>
</html>
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -27,6 +27,11 @@
'use strict';
const name = ' Ladislaus Coolio Jones '.trim();
const firstName = name.substring(0, name.indexOf(' '));
const lastName = name.substring(name.lastIndexOf(' ') + 1);
console.log(firstName); // => 'Ladislaus'
console.log(lastName); // => 'Jones'
</script>
</body>
</html>
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -25,6 +25,11 @@
const outputElement = document.querySelector('.output');
const name = 'Heribert Gold '.trim();
const firstName = name.substring(0, name.indexOf(' '));
const lastName = name.substring(name.lastIndexOf(' ') + 1);
console.log(firstName); // => 'Heribert'
console.log(lastName); // => 'Gold'
</script>
</body>
</html>
@@ -26,7 +26,11 @@
'use strict';
const outputEl = document.querySelector('.output');
const name = 'Ladislaus Jones'.trim();
const fullName = 'Ladislaus Jones'.trim();
const firstNameInitial = fullName.charAt(0);
const lastName = fullName.slice(fullName.lastIndexOf(' ') + 1);
outputEl.textContent = `${lastName}, ${firstNameInitial}.`;
</script>
</body>
</html>
@@ -26,12 +26,20 @@
<li>007 =&gt; 007</li>
</ul>
</div>
<div class="output alert alert-secondary my-3"></div>
</div>
</main>
<script>
'use strict';
let itemNumber = '123';
const outputEl = document.querySelector('.output');
let itemNumber = prompt('Your itemNumber?');
let correctedItemNumber = itemNumber.charAt(0) === '0' ? itemNumber : '0' + itemNumber;
console.log(correctedItemNumber);
outputEl.textContent = correctedItemNumber;
</script>
</body>
</html>
+39 -8
View File
@@ -35,16 +35,47 @@
<script>
'use strict';
// const QUESTION_1 = 'es geht los! Sag mir mal, welcher Operator die höhere Priorität hat: * oder + ?';
// const SOLUTION_1 = '*';
const QUESTION_1 = 'Which Operators has the higher priority: * or + ?';
const SOLUTION_1 = '*';
// const QUESTION_2 = 'Was ist das deutsche Wort für if?';
// const SOLUTION_2A = 'falls';
// const SOLUTION_2B = 'wenn';
const QUESTION_2 = "What's the German word for if";
const SOLUTION_2A = 'wenn';
const SOLUTION_2B = 'falls';
// const QUESTION_3 = 'Jetzt gib bitte einen String mit einer Länge von 8 bis 15 Zeichen ein';
// const SOLUTION_3A = 8;
// const SOLUTION_3B = 15;
const QUESTION_3 = 'Now, please enter a string with a length between 8 and 15 characters…';
const SOLUTION_3A = 8;
const SOLUTION_3B = 15;
// 1.Als ersten Schritt fragen Sie den Spieler nach seinem Namen, speichern diesen in eine Variable und begrüßen ihn mittels einer Alert-Box.
const name = prompt('Wie heißen Sie?');
alert(`Hallo ${name}`);
// 2.Stellen Sie dem Spieler die Frage, ob er sich fit genug fühlt, um gegen das dunkle JavaScript anzutreten. Es ist sinnvoll, bei der Frage die Antwortmöglichkeiten anzugeben.
const fitness = prompt('Fühlen Sie sich fit genug, um gegen das dunkle JavaScript anzutreten. ja oder nein?')
.toLowerCase()
.trim();
if (fitness === 'ja' || fitness === 'j') {
alert('Das Spiel startet! Gib alles !');
let answer = prompt(QUESTION_1);
if (answer === SOLUTION_1) {
alert('Gratulation');
let answer = prompt(QUESTION_2).toLowerCase().trim();
if (answer === SOLUTION_2A || answer === SOLUTION_2B) {
alert('Gratulation');
let answer = prompt(QUESTION_3);
if (answer.length >= SOLUTION_3A && answer.length <= SOLUTION_3B) {
alert('Gratulation');
} else {
alert('Das war falsch!');
}
} else {
alert('Das war falsch!');
}
} else {
alert('Das war falsch!');
}
} else if (fitness === 'nein') {
alert('Go Home');
}
</script>
</body>
</html>
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -19,9 +19,11 @@
const outputEl = document.querySelector('.output');
/*
TODO: Schreibe eine Funktion, die deinen Namen in der Konsole ausgibt.
*/
const logName = () => {
console.log('Philippe Torrel');
};
logName();
</script>
</body>
</html>
@@ -33,6 +33,14 @@
console.log(zahl4); // => '10.5'
const outputEl = document.querySelector('.output') || console.warn('Element existiert nicht');
// const slider = (el = null, opts) => {
// const selector = el || document.querySelector('.slider');
// // more logic
// };
// slider(document.querySelector('.my-slider'));
</script>
</body>
</html>
@@ -54,7 +54,7 @@
// toggle = false;
// }
// toggle = !toggle ? true : false;
//toggle = !toggle ? true : false;
toggle = !toggle; // => !(false) -> true | !(true) -> false
@@ -47,6 +47,7 @@
// String - Methode str.indexOf('searchValue' [, position]) - optionaler Parameter
console.log('name.indexOf("a", 2): ', name.indexOf('a', 2)); // => 6
console.log('lorem ipsum'.indexOf('m', 5)); // => 10
// Strign - Methode str.lastIndexOf('searchValue')
@@ -11,7 +11,7 @@
<div class="container py-5">
<h1>
<a href="https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/String/substr"
>String.substr(startIndex, length) DEPREACATED</a
>String.substr(startIndex, length) DEPRECATED</a
>
</h1>
<p>
@@ -28,7 +28,7 @@
// String - Methode str.charAt(index)
console.log('Lisa Simpos'.charAt(0)); // => 'L'
console.log('Lisa Simpon'.charAt(5)); // => 'S'
console.log('Lisa Simpons'.charAt(5)); // => 'S'
// Default-Wert bei keiner Angabe ist 0
console.log('Lisa Simpos'.charAt()); // => 'L'
@@ -39,6 +39,9 @@
// str.replaceAll - seit Juni 2021
outputEl.textContent = productDescription.replaceAll(productName, newProductName);
console.log('I love JS. JS is the best language'.replace('JS', 'TS'));
// => 'I love TS. JS is the best language'
console.log('I love JS. JS is the best language'.replace(/JS/g, 'TS'));
// => 'I love TS. TS is the best language'