Skip to content
Open

done #18

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
Binary file added assets/1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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">
<title>Szechuan Sauce</title>
<link rel="stylesheet" href="style.css">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="index.js" defer></script>
</head>
<body>
<header>
<h1>Rick & Morty</h1>
<img src="/assets/rickAndMorty.png" class="img">
</header>
<ul id="all-characters"></ul>
<main>
<section id="character-info">
<h3></h3>
<img src="" alt="" id="img">
<p id="first"></p>
<p id="second"></p>
</section>
<section id="character-comments-section">
<form action="" method="post">
<h2>What would this character say about Jerry?</h2>
<input type="text">
<input type="submit"></button>
</form>
<ul id="character-comments-ul"></ul>
</section>
</main>
</body>
</html>
61 changes: 61 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const allCharacters = document.querySelector('#all-characters')
const comments = document.querySelector("#character-comments-ul");
const form = document.querySelector("form")
document.addEventListener('DOMContentLoaded', () => {

form.addEventListener("submit", (e) => {
e.preventDefault();
const input = document.querySelector("input[type=text]")
const title = document.querySelector("title").textContent
const li = document.createElement("li");
li.innerHTML = `<b>${title}:</b> ${input.value}`;
comments.appendChild(li);
form.reset()

});

async function allChar() {
const results = await axios.get("https://rickandmortyapi.com/api/character")
console.log(results.data)
const infoResult = results.data.results
for(let character of infoResult) {
const item = makeCharItem(character)
allCharacters.appendChild(item)
console.log(item)
}
function makeCharItem (character) {
const li = document.createElement('li')
const img = document.createElement('img')
img.src = character.image
img.classList.add('photo-img')
li.appendChild(img)
const text = document.createElement('p')
text.textContent = character.name
li.appendChild(text)
li.addEventListener('click', () => {
const main = document.querySelector('main');
main.style.display = "flex";
const name = document.querySelector('h3')
const img = document.getElementById('img')
const status = document.getElementById('first')
const location = document.getElementById('second')
const title = document.querySelector('title')
title.textContent = character.name
name.textContent = character.name
img.src = character.image
status.innerHTML = `<b>Status</b>: ${character.status}`
location.innerHTML = `<b>Location</b>: ${character.location.name}`



})

return li
}

}
allChar();
})



Loading