From 8ca92f7373f18c50eb67126bd295855c84be2b02 Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Fri, 20 Sep 2024 14:51:30 +0200 Subject: [PATCH] half done pokemon --- oppgaver/uke7/pokemon/script.js | 44 +++++++++++++++++++++++---------- react_test/tutorial/app/page.js | 2 -- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/oppgaver/uke7/pokemon/script.js b/oppgaver/uke7/pokemon/script.js index 5412c56..e9bb379 100644 --- a/oppgaver/uke7/pokemon/script.js +++ b/oppgaver/uke7/pokemon/script.js @@ -28,19 +28,23 @@ let drowzee = { level: 33, }; +let bjarne = { + name: "Bjarne", + image: "Images/pokemonTrainerIdle.png", + pokemon: [], +} let possiblePokemon = [pikachu, bulbasaur, oranguru, drowzee]; let randomPokemon = null; -let playerName = "Bjarne"; -let playerImage = "/Images/pokemonTrainerIdle.png"; -let playerPokemon = []; - let app = document.getElementById("app"); updateView(); function updateView() { getRandomPokemon() + // randomPokemon.level = Math.floor(Math.random() * 100) + // randomPokemon.health = Math.floor(Math.random() * 100) + // console.log(randomPokemon.level, randomPokemon.health); app.innerHTML = /*HTML*/ `
@@ -51,8 +55,8 @@ function updateView() {
- -
${playerName}
+ +
${bjarne.name}
@@ -66,10 +70,10 @@ function updateView() { `; } -function caughtPokemonView(){ +function caughtPokemonView() { app.innerHTML = /*HTML*/`
-

Du fanget ${playerPokemon[playerPokemon.length - 1].name}

+

Du fanget ${bjarne.pokemon[bjarne.pokemon.length - 1].name}

@@ -78,16 +82,30 @@ function caughtPokemonView(){ `; } -function catchPokemon(){ - playerPokemon.push(randomPokemon); +function catchPokemon() { + bjarne.pokemon.push(randomPokemon); caughtPokemonView(); } -function showPokemon(){ - console.log(playerPokemon); +function showPokemon() { + app.classList = ''; + app.innerHTML = ''; + + for (i = 0; i < bjarne.pokemon.length; i++){ + app.innerHTML += /*HTML*/ ` + + +
NavnLevel
${bjarne.pokemon[i].name}${bjarne.pokemon[i].level}
+ `; + } + app.innerHTML += /*HTML*/` +
+ +
+ `; } -function getRandomPokemon(){ +function getRandomPokemon() { let randomNum = Math.floor(Math.random() * possiblePokemon.length); randomPokemon = possiblePokemon[randomNum]; } diff --git a/react_test/tutorial/app/page.js b/react_test/tutorial/app/page.js index 0d2935c..54ddc7e 100644 --- a/react_test/tutorial/app/page.js +++ b/react_test/tutorial/app/page.js @@ -6,8 +6,6 @@ function Header({ title }) { export default function HomePage() { const names = ['Ada Lovlace', 'Grace Hopper', 'Margaret Hamilton']; - - return (