lab-development-imb/web/10/labor/10_loesungen/Aufgabe_2/paw.js

44 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const helden = {
"Chase": "Chase ist auf Spur!",
"Marshall": "Ich bin startklar!",
"Skye": "Diese Pfote hebt ab!",
"Rocky": "Wegwerfen? Kommt nicht in die Tüte!",
"Rubble": "Rubble ist zur Stelle!",
"Zuma": "Los gehts ins Wasser!",
"Everest": "Eis und Schnee ich bin bereit!",
"Tracker": "Ich höre alles!",
};
//
const formular = document.getElementById("pawFormular");
const meldung = document.getElementById("meldung");
const spruch = document.getElementById("spruch");
const name = document.getElementById("name");
formular.addEventListener("submit", ev =>{
ev.preventDefault(); // verhindert neuladen
const eingabe = name.value.trim();
let gefunden = false;
for(let h in helden){
if(h.toLowerCase() === eingabe.toLowerCase()){
gefunden = true;
break
}
}
if(!eingabe || !gefunden){
meldung.textContent = "Bitte gib einen echten Paw Patrol Helden an";
spruch.textContent = "";
return;
}
meldung.textContent = "Gute Wahl " + eingabe + " ist dabei!";
spruch.textContent = helden[eingabe];
});