Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavaScript script to manipulate a json object and print it in a human…
… legible format
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
# Article-Data-Processor | ||
A JavaScript-based solution to fetch, process, and display article data from a provided list. | ||
## Installation | ||
|
||
1. Clone the repository: | ||
``` | ||
git clone https://github.com/FeverCode/Article-Data-Processor.git | ||
``` | ||
|
||
2. Navigate to the repository: | ||
``` | ||
cd Article-Data-Processor | ||
``` | ||
|
||
## Usage | ||
|
||
1. Open the `Task 1 - Intern.html` file in your preferred web browser. | ||
2. View the processed and formatted article data in the "Results of my code" section. | ||
|
||
## Contributing | ||
|
||
Pull requests are welcome. For major changes, please open an issue first to discuss what you'd like to change. | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](LICENSE). See the [LICENSE](LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>FeverCode - Task 1</title> | ||
<style>.block { background-color:gainsboro; padding:1em; } </style> | ||
</head> | ||
<body> | ||
<h1>FeverCode - Task 1</h1> | ||
<h2>My code:</h2> | ||
<p id="code" class="block"></p> | ||
<h2>Results of my code:</h2> | ||
<p id="results" class="block"></p> | ||
<script id="task_id"> | ||
// {# INPUT #} | ||
let data = [ | ||
{"page_id": 6682420, "creation_date": "2021-09-13", "title": "André Baniwa"}, | ||
{"page_id": 4246775, "creation_date": "2013-12-10", "title": "Benki Piyãko"}, | ||
{"page_id": 5882073, "creation_date": "2018-12-03", "title": "Célia Xakriabá"}, | ||
{"page_id": 6977673, "creation_date": "2022-10-05", "title": "Chirley Pankará"}, | ||
{"page_id": 7069044, "creation_date": "2023-02-16", "title": "Cristine Takuá"}, | ||
{"page_id": 2119511, "creation_date": "2009-01-28", "title": "Eliane Potiguara"}, | ||
{"page_id": 6714407, "creation_date": "2021-10-09", "title": "Jaider Esbell"}, | ||
{"page_id": 6977117, "creation_date": "2022-10-04", "title": "Jerônimo Rodrigues"}, | ||
{"page_id": 6935831, "creation_date": "2022-08-02", "title": "Nanblá Gakran"}, | ||
{"page_id": 4908665, "creation_date": "2015-11-13", "title": "Sônia Guajajara"}, | ||
{"page_id": 5886895, "creation_date": "2018-12-12", "title": "Vãngri Kaingáng"}, | ||
{"page_id": 6549130, "creation_date": "2021-04-10", "title": "Zezico Guajajara"}, | ||
]; | ||
|
||
|
||
// {# YOUR CODE HERE #} | ||
// Function to format the date as "MONTH DAY, YEAR" | ||
function formatDate(dateString) { | ||
const options = { year: 'numeric', month: 'long', day: 'numeric' }; | ||
return new Date(dateString).toLocaleDateString(undefined, options); | ||
} | ||
|
||
// Get the element with ID "results" | ||
const resultsElement = document.getElementById("results"); | ||
|
||
// Process each item in the data array and append the formatted string to the resultsElement | ||
data.forEach(item => { | ||
const formattedString = `Article "${item.title}" (Page ID ${item.page_id}) was created at ${formatDate(item.creation_date)}.<br>`; | ||
resultsElement.innerHTML += formattedString; | ||
}); | ||
|
||
</script> | ||
<script> | ||
document.getElementById("code").innerText = document.getElementById("task_id").text; | ||
</script> | ||
</body> | ||
</html> |