Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
header > h1 {
font-family: fantasy;
color: white;
}

body {
background-color: black;
color: white;
display: column;
flex-direction: column;
align-items: center;
}
header > img {
height: 100px;
width: 100px;
}

header {
height: 150px;
width: 70%;
display: flex;
justify-content: space-between;
padding: 0 30px;
align-items: center;
margin-bottom: 20px;
background-color: green;
}

#all-characters {
display: flex;
list-style: none;
flex-direction: row;
width: 70%;
padding:0;
margin:0;
overflow-x: scroll;
}

main {
width: 70%;
display: none;
border: 5px solid white;
}

input[type="text"]{
width: 380px;
}
26 changes: 26 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,35 @@
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>"Szechuan Sauce"</title>
<link rel="icon" type="image/png" href="./assets/favicon.jpeg"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="index1.js" defer></script>
</head>
<body>
<header>
<h1>Rick & Morty</h1>
<img src="./../assets/rickAndMorty.png" alt="rickAndMorty">
</header>

<ul id="all-characters"></ul>
<main>
<section id="character-info">
<h3 id="character-name"></h3>
<img id="character-img">
<p id="character-status"></p>
<p id="character-location"></p>
</section>
<section id="character-comments-section">
<form >
<input type="text" id="comment">
<input type="submit">
</form>
<ul id="character-comments-ul"></ul>
</section>
</main>

</body>
</html>
59 changes: 59 additions & 0 deletions index1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@


const allCharacters = document.querySelector("#all-characters")
const main = document.querySelector("main")
const name = document.querySelector("#character-name")

const status = document.querySelector("#character-status")

const image = document.querySelector("#character-img")
const place = document.querySelector("#character-location")
const title = document.querySelector("title")
const form = document.querySelector("form")
const comments = document.querySelector("#character-comments-ul")
const getAllCharacters = async () => {
try {

const res = await axios.get("https://rickandmortyapi.com/api/character")

res.data.results.forEach(character => {
const li = document.createElement("li")
const img = document.createElement("img")
const p = document.createElement("p")
img.src = character.image
img.value = character.id
p.innerText = character.name
li.appendChild(img)
li.appendChild(p)
allCharacters.appendChild(li)
})
}
catch (err) {
console.log(err)
}
}

getAllCharacters()


allCharacters.addEventListener("click", async (e) => {
main.style.display ="flex";
const url = `https://rickandmortyapi.com/api/character/${e.target.value}`
const res = await axios.get(url)
name.innerText = res.data.name
image.src = res.data.image
status.innerHTML = `<b>Status</b> ${res.data.status}`
place.innerHTML = `<b>Location</b> ${res.data.location.name}`
title.innerText = res.data.name
})

form.addEventListener("submit", (e)=> {
e.preventDefault()
const comment = document.querySelector("#comment")
const li = document.createElement("li")
debugger
li.innerHTML = `<b>${title.textContent}:</b> ${comment.value}`
comments.appendChild(li)
comment.value = ""

})
Loading