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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
58 changes: 58 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
header {
display: flex;
justify-content: space-around;
background-color: green;
height: 150px;
margin: auto;
width: 70%;
align-items: center;
margin-bottom: 20px;
}

h1 {
font-family: fantasy;
color: white;
font-size: 50px;
}

header > img {
height: 100px;
}

body {
display: flex;
background-color: black;
flex-direction: column;
align-items: center;
color: white;
}

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

input[type="text"] {
width: 380px;
}

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

#character-info {
text-align: center;
}

#character-comments-section {
display: flex;
justify-content: center;
align-items: center;
}
25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<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="./index.js" defer ></script>
<title> Szechuan Sauce</title>
</head>
<body>
<header>
<img src="./assets/rickAndMorty.png" alt="rickAndMorty-hugging">
<h1>Rick & Morty</h1>
</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 id="comment" type="text">
<input type="submit" value="Comment">
</form>
<ul id="character-comments-ul"></ul>
</section>
</main>
</body>
</html>
53 changes: 53 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@


const allCharacters = document.querySelector("#all-characters");
const main = document.querySelector("main");
const name = document.querySelector("#character-name")
const image = document.querySelector("#character-img")
const status = document.querySelector("#character-status")
const place = document.querySelector("#character-location")
const title = document.querySelector("title");
const form = document.querySelector("form");
const ul = document.querySelector("#character-comments-ul");

const getAllChar = 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")
console.log(character)
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(error)
}
}
getAllChar()

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 li = document.createElement("li");
const comment = document.querySelector("#comment").value;
li.innerHTML = `<b>${title.textContent}:<b> ${comment}`
ul.appendChild(li);
form.reset()
})
Loading