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
85 changes: 85 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
body {
background-color: rgb(0, 0, 0);
display: flex;
flex-direction: column;
align-items: center;
color: rgb(255, 255, 255);
}

header {
display: flex;
justify-content: space-around;
align-items: center;
font-size: 1.6em;
background-color: rgb(0, 128, 0);
width: 70%;
height: 150px;
}

#header-img {
height: 100px;
}

h1 {
font-family: fantasy;
}

.photo-img {
width: 150px;
}

#all-characters {
display: flex;
width: 70%;
overflow: scroll;
overflow-y: hidden;
margin: 20px;
padding: 0px;
list-style-type: none;
}

#all-characters li {
text-align: center;
}

main {
display: none;
}

.main-show {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
width: 70%;
font-size: 1.1em;
border: 3px solid rgba(255, 217, 0, 0.8);
}

#input-comment {
width: 380px;
}

#character-info {
display: flex;
flex-direction: column;
align-items: center;
}

#character-comments-section {
display: flex;
flex-direction: column;
align-items: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
#form-submit {
margin: 5px;
}

#character-comments-ul {
align-self: flex-start;
padding: 0px 0px 0px 15px;
}
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@
<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="./index.css">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="./index.js"></script>
</head>
<body>
<header>
<h1>Rick & Morty</h1>
<img id="header-img" src="./assets/rickAndMorty.png" alt="">
</header>
<ul id="all-characters"></ul>
<main>
<section id="character-info">
</section>
<section id="character-comments-section">
<h3>What would this character say about Jerry?</h3>
<form>
<input type="text" id="input-comment" required>
<input type="submit" id="form-submit">
</form>
<ul id="character-comments-ul"></ul>
</section>
</main>
</body>
</html>
48 changes: 48 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
document.addEventListener("DOMContentLoaded", async () => {
await axios.get("https://rickandmortyapi.com/api/character")
.then(response => {
for(const char of response.data.results){
const li = document.createElement("li")
const img = document.createElement("img")
const p = document.createElement("p")
img.className = "photo-img"
img.src = char.image
p.textContent = char.name
li.append(img, p)
li.addEventListener("click", ()=> {
document.title = char.name
const main = document.querySelector("main")
if(main.className !== "main-show"){
main.className = "main-show"
}
const section = document.getElementById("character-info")
const h3 = document.createElement("h3")
const img1 = document.createElement("img")
const p1 = document.createElement("p")
const p2 = document.createElement("p")
h3.id = "name"
h3.textContent = char.name
img1.src = char.image
p1.innerHTML = `<b>Status:</b> ${char.status}`
p2.innerHTML = `<b>Location:</b> ${char.location.name}`
section.innerHTML = ""
section.append(h3, img1, p1, p2)
})
document.getElementById("all-characters").append(li)
}
})

const form = document.querySelector("form")
form.addEventListener("submit", event => {
event.preventDefault()
const userInput = document.querySelector("input")
if(!userInput.value.trim()){
userInput.value = ""
return
}
const li = document.createElement("li")
li.innerHTML = `<b>${document.getElementById("name").textContent}:</b> ${userInput.value}`
document.getElementById("character-comments-ul").append(li)
userInput.value = ""
})
})