Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Homework for first week js2 - #504

Closed
Jalalalattar wants to merge 4 commits into
HackYourFuture:masterfrom
Jalalalattar:master
Closed

Homework for first week js2#504
Jalalalattar wants to merge 4 commits into
HackYourFuture:masterfrom
Jalalalattar:master

Conversation

@Jalalalattar

Copy link
Copy Markdown

Review

<body>
<h1>My book list</h1>

<script>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice it is rare to have script inside of a script tag. Try to keep JavaScript external by moving the code to . a separate js file and using src attribute in script element to reference it for example

<script src='./1-books.js' type='text/javascript'></script>

The separate code makes it easier for web browsers to cache which enhances performance (here is an article about javascript performance optimisation https://www.keycdn.com/blog/javascript-performance)

title : 'Underworld',
author : 'Don DeLillo',
alreadyRead :true
}

@neveenatik neveenatik Dec 23, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excercise requires three favourite books I see only two 😛

// 5

if (obj.alreadyRead === true) {
p.style.color = 'green';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of using an inline style you can have a css file with class red/green (for example) and toggle classes here is an article that explains more about this:
https://javascript.info/styles-and-classes

for (let obj of books) {
// 2
const p = document.createElement('p');
p.innerText = `${obj.title} was written by ${obj.author.toUpperCase()}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of templating 😉

}
// 4
let img1 = document.createElement('img');
let img2 = document.createElement('img');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you have img outside the for of loop. Think about how is img1 different than img2 and how can you solve that. In the end you need an image for each book right?

let img2 = document.createElement('img');
img1.src = 'https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/ArtistOfTheFloatingWorld.jpg/220px-ArtistOfTheFloatingWorld.jpg';
img2.src = 'http://xoxoafterdark.com/wp-content/uploads/2014/10/Delillo-Underworld.jpg';
let lis = document.querySelectorAll('li');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about why would you query the list items you already have them inside of the for of loop right?

img1.src = 'https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/ArtistOfTheFloatingWorld.jpg/220px-ArtistOfTheFloatingWorld.jpg';
img2.src = 'http://xoxoafterdark.com/wp-content/uploads/2014/10/Delillo-Underworld.jpg';
let lis = document.querySelectorAll('li');
lis[0].appendChild(img1).style.width = '350px';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again classes vs inline style 🙂

<li>Favorite food: <span id="fav-food"></span></li>
<li>Hometown: <span id="hometown"></span></li>
</ul>
<script>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as exercise one javascript and style better be in external files (unless exercise indicates to do so) 👍

document.querySelector('#hometown').innerText='London';

const items=document.querySelectorAll('ul li');
items.forEach(item=> {item.classList.add('list-item')})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. However good to keep in mind that this way of iterating is not supported by all browsers Here is more read about iteration options on nodeList
https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/


const styleTag=document.createElement('style');
document.querySelector("head").appendChild(styleTag);
document.querySelector('style').innerText= '.list-item {color:red}'

@neveenatik neveenatik Dec 23, 2019

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you misunderstood the requirement here or got carried away manipulating using javascript 😄
image
The idea is to add a tag in the html file and have a css file with the class list-item which sets font color to red.


const img = document.createElement('img');
img.src = 'https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/d9585883-0c30-448b-8cee-6eac6d5c695f/d80kp71-a8d13ec7-6e9a-4268-9312-222184443314.png/v1/fill/w_1024,h_576,q_75,strp/real_madrid_david_beckham_wallpaper_by_sameerhd-d80kp71.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwic3ViIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl0sIm9iaiI6W1t7InBhdGgiOiIvZi9kOTU4NTg4My0wYzMwLTQ0OGItOGNlZS02ZWFjNmQ1YzY5NWYvZDgwa3A3MS1hOGQxM2VjNy02ZTlhLTQyNjgtOTMxMi0yMjIxODQ0NDMzMTQucG5nIiwid2lkdGgiOiI8PTEwMjQiLCJoZWlnaHQiOiI8PTU3NiJ9XV19.DsmMSnKtljCP7zEAAUsax4S3Lf9oASSChxWHmyPAT0g'
document.body.appendChild(img);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work 👍

@@ -0,0 +1,7 @@
function hijackGoogleLogo () {
let googleImage=document.querySelector('#hplogo')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this selector didn't work on my google version it would be interesting to see if it works on yours. can you make a screenshot of the element with this id ?


<body>
<div id="klok"></div>
<script src="./showCurrentTime.js">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you renamed your javascirpt file and forgot to update the src here therefore currently code doesn't run 😨

<head>
<title>Klok :)</title>
<style>
div {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the same reason explained above I believe it is better to use a css file and keep style in there instead of internal style tag

const tijd = datum.toLocaleTimeString();
document.querySelector('#klok').innerHTML = tijd;
}
setInterval(eenklok, 1000); No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 👍

function catWalk() {

setInterval(frame, 50)
function frame() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work however I wouldn't declare a function inside of a function simply because no one can use the inner function outside the outer function.
I think it would be better to keep all functionality inside of catWalk function and then call catWalk with setInterval every 50 ms.

function catWalk() {
    ... all functionality
}

setInterval(catWalk, 50);

setInterval(frame, 50)
function frame() {

left = left > 1500 ? 0 : left;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the screen size is less than 1500? maybe look into getting the screen width using javascript for example using window.screen.width from webAPI
https://developer.mozilla.org/en-US/docs/Web/API/Screen/width


}
} else {
img.style.left;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what did you want to do here it looks like you have read the img.style.left but didn't change or store it!

@neveenatik neveenatik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work I liked the way you solved these exercises I left some comments for you please reach out through slack if any of these points aren't explained well to you 🙂
I also noticed you forgot to submit Project: Random Quote Generator

@NoerGitKat NoerGitKat closed this Mar 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants