-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
review requested #1
base: for-review
Are you sure you want to change the base?
Changes from 12 commits
813d08b
c6696d5
bc05c6f
3044dac
a44ad91
72351c2
a22bacb
fc31628
9f98877
0014953
84532e9
40ebf7f
2b9dbd6
e1cb0be
4ffee05
6999652
66ea2f7
8ee867d
4cafd5f
ea98648
4579ae3
c8cc93a
356c2a3
c595902
181d9c6
8c176c0
5586705
5bde5eb
7d1263e
1ac596c
2a9013c
02f412a
eeacbbb
20bfc82
9cf33d2
10b4abb
7e6c407
a9699f0
9dabbb0
5d52c2e
fbd06bd
46ef940
f00a753
6556e99
b93df4d
77696bf
fbaa50e
50cc630
6354dc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
|
||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/script.js" | ||
} | ||
] | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job getting everything working up to level-300! I think it was optional anyway, but the only thing missing in terms of functionality is being able to easily go back to seeing all episodes after using the dropdown - the only way to get them back right now is to start typing and then delete again. I think in terms of style/readability, it's good to break up code into some smaller sub-functions - it can make the code much easier to read (because usually a function says what it does), and easier for you to think about too. There is a lot happening in these functions! And the 300 level bit could be put ("encapsulated") in a function. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,102 @@ | ||
//You can edit ALL of the code here | ||
let allEpisodes = getAllEpisodes(); | ||
function setup() { | ||
const allEpisodes = getAllEpisodes(); | ||
//let allEpisodes = getAllEpisodes(); | ||
makePageForEpisodes(allEpisodes); | ||
} | ||
|
||
//level 100 | ||
//showing all episodes | ||
|
||
function makePageForEpisodes(episodeList) { | ||
const rootElem = document.getElementById("root"); | ||
rootElem.textContent = `Got ${episodeList.length} episode(s)`; | ||
let rootElem = document.getElementById("root"); | ||
// rootElem.textContent = `Got ${episodeList.length} episode(s)`; | ||
rootElem.innerHTML = ""; | ||
for(let episode of episodeList) { | ||
let divEle = document.createElement("div"); | ||
divEle.className = "card"; | ||
|
||
const episodeName =document.createElement("h1"); | ||
episodeName.innerText = `${episode.name}-S${(String(episode.season).padStart(2,'0'))}E${String(episode.number).padStart(2,'0')}`; | ||
const lineEle = document.createElement("div"); | ||
lineEle.className = "l"; | ||
|
||
|
||
const image = document.createElement("img"); | ||
image.src = episode.image.medium; | ||
|
||
const episodeSummary = document.createElement("p"); | ||
episodeSummary.innerHTML = episode.summary; | ||
|
||
divEle.append( | ||
episodeName, | ||
lineEle, | ||
image, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i learn from you too :) i didn't know you can add them all at one go, cool!! |
||
episodeSummary, | ||
); | ||
rootElem.append(divEle) | ||
}; | ||
} | ||
window.onload = setup; | ||
|
||
//level 200 | ||
//search bar | ||
|
||
searchEle = document.querySelector("#search") | ||
searchEle.addEventListener("input", searchEpisode); | ||
|
||
function searchEpisode(){ | ||
const searchInput = searchEle.value.toLowerCase(); | ||
const filteredEpisodes = allEpisodes.filter(episode => { | ||
if (episode.name.toLowerCase().includes(searchInput) || episode.summary.toLowerCase().includes(searchInput)){ | ||
return episode; | ||
} | ||
}) | ||
|
||
document.querySelector("#num").innerText = filteredEpisodes.length; | ||
makePageForEpisodes(filteredEpisodes); | ||
|
||
} | ||
|
||
//level 300 | ||
//select bar | ||
|
||
let selectEle = document.querySelector("#selector"); | ||
let optionEle = document.createElement("option") | ||
optionEle.innerText= "Select Episodes"; | ||
selectEle.appendChild(optionEle); | ||
|
||
allEpisodes.forEach(el => { | ||
let options = document.createElement("option"); | ||
options.value = el.name; | ||
options.innerText = `${el.name} - S${el.season.toString().padStart(2, "0")}E${el.number.toString().padStart(2, "0")}`; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wise approach for padStart() |
||
selectEle.appendChild(options); | ||
}); | ||
|
||
selectEle.addEventListener("change", function () { | ||
let selected = selectEle.value; | ||
let episodes = Array.from(document.getElementsByClassName("card")); | ||
|
||
episodes.forEach((episode) => { | ||
let h1Element = episode.querySelector("h1"); | ||
if (h1Element.innerText.includes(selected)) { | ||
episode.style.display = "block"; | ||
document.querySelector("#num").innerText = 1; | ||
|
||
} else { | ||
episode.style.display = "none"; | ||
} | ||
}); | ||
}); | ||
|
||
//footer | ||
|
||
let footerEle= document.getElementById("footer"); | ||
const footerLink = document.createElement("a"); | ||
footerLink.href = "https://www.tvmaze.com/" | ||
footerLink.textContent = "data from tvmaze.com"; | ||
footerEle.appendChild(footerLink); | ||
|
||
window.onload = setup; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,55 @@ | ||
#root { | ||
color: red; | ||
color:black; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
} | ||
|
||
.card { | ||
display: flex; | ||
flex-direction: column; | ||
margin : 10px; | ||
padding : 32px; | ||
background-color:azure; | ||
max-width: 300px; | ||
border-radius: 3%; | ||
border: 1px solid orchid; | ||
|
||
} | ||
|
||
|
||
|
||
h1{ | ||
font-size: 20px; | ||
} | ||
|
||
.l { | ||
margin-bottom: 20px; | ||
border: 1px solid orchid; | ||
|
||
} | ||
|
||
|
||
img { | ||
align-self: center; | ||
} | ||
|
||
p{ | ||
text-align: justify; | ||
} | ||
|
||
#search , #selector { | ||
color: green; | ||
padding: 10px; | ||
border: 2px solid orchid; | ||
margin-bottom: 20px; | ||
} | ||
|
||
#footer { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
font-size: 20px; | ||
font-family: cursive; | ||
color: red; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VS code settings are usually not committed, you could add this file to your gitignore.