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
31 changes: 31 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>

<body>
<div id="topnav" class="flex-grid">
<h3><a class="active" href="#home">Home</a></h3>
<h3><a href="#news">News</a></h3>
<h3><a href="#media">Media</a></h3>
</h3><input type="text" placeholder="Search.."></h3>
</div>
<div id="header" class=flex-grid>
<h1>The Daily News</h1>
</div>

<div class="site">
<div id="article" class="wrapper"></div>
</div>


<script src="index.js"></script>
</body>

</html>
74 changes: 74 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function displayData(articles) {
const stories = document.querySelector("#article");
articles.map(article => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't use the output of a map method, it's better to replace it with a forEach instead

let div = document.createElement("div");
Copy link
Contributor

Choose a reason for hiding this comment

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

It might easier to implement this part using HTML string templates

stories.appendChild(div);

let title = document.createElement("h3");
title.textContent = article.title;
div.appendChild(title);
image = document.createElement("img");
image.setAttribute(
"src",
article.urlToImage || "http://placekitten.com/200/300"
);
image.setAttribute("alt", article.title || "Nothing to see here");
image.setAttribute("height", "100px");
image.setAttribute("width", "150px");
div.appendChild(image);

let description = document.createElement("h4");
description.textContent = article.description;
div.appendChild(description);

let source = document.createElement("h5");
source.textContent = article.source.name;
div.appendChild(source);

let datePublished = document.createElement("div");
datePublished.textContent = article.publishedAt;
div.appendChild(datePublished);

let button = document.createElement("a");
button.textContent = "Original Source";
button.setAttribute("href", article.url);
div.appendChild(button);

// function articleSearch() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code can be removed so it does not take up space on the page

// let input = document.getElementById("article.description").placeholder {

// }

// filter = input.value.toUpperCase(result);
// }

console.log(
"title :",
article.title,
"image ",
article.urlToImage,
"desc :",
article.description,
"source",
article.source.name,
"date",
article.publishedAt,
"link:",
article.url
);
});
}

fetch(
"https://newsapi.org/v2/top-headlines?country=gb&apiKey=b7b5bf6dda374f2086f391c826337994"
)
.then(function(response) {
return response.json();
})
.then(function(body) {
console.log(body.articles);
displayData(body.articles);
})
.catch(function(error) {
console.log(error);
});
63 changes: 63 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.site {
background-color: whitesmoke;
padding: 5px;
flex-grow: 4;
}

#header {
display: flex;
flex-direction: row;
flex-wrap: wrap;
font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
font-size: 12px;
font-weight: 300;
padding: 1px;
align-content: space-between;
background-color: lightgrey;
}

#topnav {
display: flex;
flex-direction: row;
flex-wrap: wrap;
text-align: center;
justify-content: space-evenly;
padding: 14px 16px;
flex-grow: inherit;
font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
"Lucida Sans Unicode", Geneva, Verdana, sans-serif;
font-size: 12px;
background: lavender;
color: black;
}

.topnav a:hover {
color: red;
}
.topnav input[type="text"] {
float: right;
padding: 6px;
border: none;
margin-top: 8px;
margin-right: 16px;
font-size: 17px;
}

.wrapper {
display: grid;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice to see grid being used

grid-template-columns: 50% 50%;
font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
"Lucida Sans Unicode", Geneva, Verdana, sans-serif;
font-size: 12px;
}

.wrapper > div {
background: silver;
padding: 0.5em;
}

@media (max-width: 1024px) {
.wrapper {
grid-template-columns: 100;
}
}