Her er min kode med mit forsøg med brug af koden: "document.getElementById("imageid").src="xxxxx.jpg": som ikke virker, i den form jeg har gjort.
Magler der et output også? Plz hjælp
<head>
<title>Airbus flight calculator</title>
</head>
<body>
<h1 id="h1Title">The lil' mascot, Tamacotshi</h1>
<img src="
https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/54adb844-d78c-4a63-9a83-b6229792972b/db22ojd-c1c385c7-ee3a-4c32-9d34-353ed17930e6.gif?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzU0YWRiODQ0LWQ3OGMtNGE2My05YTgzLWI2MjI5NzkyOTcyYlwvZGIyMm9qZC1jMWMzODVjNy1lZTNhLTRjMzItOWQzNC0zNTNlZDE3OTMwZTYuZ2lmIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.whCUGjVcQDzeY6ENc3QoAkIirPCUnqdzXNYjcXKpiN4" width="200">
<div>
<button onclick="eatButtonPressed()">Eat</button>//output??
<button onclick="playButtonPressed()">Play</button>//output??
</div>
<script>
class Mascot {
level = 1
currentMood = new Happy (this);
eat(){
this.currentMood.eat()
console.log("level " + this.level + " mood " + this.currentMood)
}
play(){
this.currentMood.play()
console.log("level " + this.level + " mood " + this.currentMood)
}
change(mood) {
this.currentMood = mood
}
}
class Mood {
constructor(mascot) {
this.mascot = mascot;
}
}
class Hungry extends Mood {
toString(){
return "Hungry"
}
eat() {
console.log("happy")
this.mascot.change(new Happy(mascot));
}
play(){
console.log("Cannot play with a mascot that is hungry")}
}
class Happy extends Mood {
notEaten = true;
notPlaying = true
toString(){
return "Happy and notEaten " + this.notEaten + " and notPlaying " + this.notPlaying
}
eat() {
this.notPlaying=true
if (this.notEaten){
this.mascot.level++;
this.notEaten=false;
document.getElementById("imageid").src="
https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/54adb844-d78c-4a63-9a83-b6229792972b/db22ojd-c1c385c7-ee3a-4c32-9d34-353ed17930e6.gif?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzU0YWRiODQ0LWQ3OGMtNGE2My05YTgzLWI2MjI5NzkyOTcyYlwvZGIyMm9qZC1jMWMzODVjNy1lZTNhLTRjMzItOWQzNC0zNTNlZDE3OTMwZTYuZ2lmIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.whCUGjVcQDzeY6ENc3QoAkIirPCUnqdzXNYjcXKpiN4"; }
else {
this.mascot.change(new Bored(mascot));
document.getElementById("imageid").src="
https://www.andlighten.nl/wp-content/uploads/2018/03/Mametchi_sleepy.gif";}
}
play()
{
this.notEaten=true
if (this.notPlaying){
this.mascot.level=this.mascot.level+2;
this.notPlaying=false;
}
else {
this.mascot.change(new Hungry(mascot));
document.getElementById("imageid").src="
https://www.andlighten.nl/wp-content/uploads/2018/03/Mametchi_toilet.gif";}
}
}
class Bored extends Mood {
moreThanAnHour=false;
toString(){
return "Bored"
}
eat (){
if (moreThanAnHour){
this.mascot.change(new Happy(mascot));
document.getElementById("imageid").src="
https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/54adb844-d78c-4a63-9a83-b6229792972b/db22ojd-c1c385c7-ee3a-4c32-9d34-353ed17930e6.gif?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzU0YWRiODQ0LWQ3OGMtNGE2My05YTgzLWI2MjI5NzkyOTcyYlwvZGIyMm9qZC1jMWMzODVjNy1lZTNhLTRjMzItOWQzNC0zNTNlZDE3OTMwZTYuZ2lmIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.whCUGjVcQDzeY6ENc3QoAkIirPCUnqdzXNYjcXKpiN4";}
else {
moreThanAnHour=true;
console.log("you cannot play with the mascot");
}
}
play (){
this.mascot.change(new Happy(mascot));
}
}
let mascot = new Mascot();
mascot.play();
</script>
</body>
</html>