Question

In: Computer Science

Make sure it works on jsfiddle and keep the code seperate html: css: javascript: -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Make sure it works on jsfiddle

and keep the code seperate

html:

css:

javascript:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Assignment

You should already have some experience with jQuery and some simple experience with JSON (from charting). In this assignment we will be creating some JSON data, parsing it, and displaying it.

Step 1 – If you are not familiar with JSON you should complete the JSON tutorial at w3schools

Step 2- You will now create a JSON file to represent some data of your own making some examples of data that you could create such as A sports score database ex. players, playerName, season, and scoring. Feel free to create data on something that is of interest to you (and share on the discussion board).

Step 3 – Validate your JSON (you can use JSON Lint) jsonlint.c o m  and save it to your server as a text file.

Step 4 – In a web page, read the JSON data and display the data in a nice human readable format (table or list). This is demonstrated in the W3Schools tutorial.

Information

Solutions

Expert Solution

Here's the json data used in the solution. You can validate it on jsonlint.com if you want.

{
        "status": "success",
        "data": [{
                "id": "1",
                "employee_name": "Tiger Nixon",
                "employee_salary": "320800",
                "employee_age": "61"
        }, {
                "id": "2",
                "employee_name": "Garrett Winters",
                "employee_salary": "170750",
                "employee_age": "63"
        }, {
                "id": "3",
                "employee_name": "Ashton Cox",
                "employee_salary": "86000",
                "employee_age": "66"
        }, {
                "id": "4",
                "employee_name": "Cedric Kelly",
                "employee_salary": "433060",
                "employee_age": "22"
        }, {
                "id": "5",
                "employee_name": "Airi Satou",
                "employee_salary": "162700",
                "employee_age": "33"
        }]
}

Since only html, css and javascript files are asked in the question and it needs to work on jsfiddle, I'm just going to use this json data as it is in the code, instead of requesting it from a server. A server can also be written to send the json file and the code will work just fine. You can also parse the JSON data stored as a string using JSON.parse() method in JavaScript. For example,

const data = JSON.parse('{"status":"success","data":[{"id":"1","employee_name":"Tiger Nixon","employee_salary":"320800","employee_age":"61"},{"id":"2","employee_name":"Garrett Winters","employee_salary":"170750","employee_age":"63"},{"id":"3","employee_name":"Ashton Cox","employee_salary":"86000","employee_age":"66"},{"id":"4","employee_name":"Cedric Kelly","employee_salary":"433060","employee_age":"22"},{"id":"5","employee_name":"Airi Satou","employee_salary":"162700","employee_age":"33"}]}')
console.log(data);

Working jsfiddle: https://jsfiddle.net/helek91076/yg91nk35/3/

JavaScript

/* jsonData can be requested from a server as well. */
const jsonData = JSON.parse('{"status":"success","data":[{"id":"1","employee_name":"Tiger Nixon","employee_salary":"320800","employee_age":"61"},{"id":"2","employee_name":"Garrett Winters","employee_salary":"170750","employee_age":"63"},{"id":"3","employee_name":"Ashton Cox","employee_salary":"86000","employee_age":"66"},{"id":"4","employee_name":"Cedric Kelly","employee_salary":"433060","employee_age":"22"},{"id":"5","employee_name":"Airi Satou","employee_salary":"162700","employee_age":"33"}]}')

const tableRef = document.getElementsByClassName('jsonTable')[0].getElementsByTagName('tbody')[0];

jsonData.data.forEach(row => {
        // Add new row
  const newRow   = tableRef.insertRow();
  // Insert cells
  const id  = newRow.insertCell(0);
  id.appendChild(document.createTextNode(row.id));
  const name  = newRow.insertCell(1);
  name.appendChild(document.createTextNode(row.employee_name));
  const salary  = newRow.insertCell(2);
  salary.appendChild(document.createTextNode(row.employee_salary));
  const age  = newRow.insertCell(3);
  age.appendChild(document.createTextNode(row.employee_age));
})

HTML

<table class="jsonTable">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Salary</th>
            <th>Age</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

CSS

.jsonTable {
    border: solid 1px #DDEEEE;
    border-collapse: collapse;
    border-spacing: 0;
}
.jsonTable thead th {
    background-color: #DDEFEF;
    border: solid 1px #DDEEEE;
    color: #336B6B;
    padding: 10px;
    text-align: left;
    text-shadow: 1px 1px 1px #fff;
}
.jsonTable tbody td {
    border: solid 1px #DDEEEE;
    color: #333;
    padding: 10px;
    text-shadow: 1px 1px 1px #fff;
}

Related Solutions

write php code for buying and selling web using sql, javascript ,html ,css style
write php code for buying and selling web using sql, javascript ,html ,css style
JAVASCRIPT HTML I'm looking to make a function that will take a postal code in a...
JAVASCRIPT HTML I'm looking to make a function that will take a postal code in a text box. The function jobs is to basically make sure the first letter of the postal code starts with these letters. ('A') ('N") ('W') ('F'). If the first letter of the postal code does not match up then an error to the user is sent.
Build an application using HTML, CSS, javascript, json. It is not necessary for backend to be...
Build an application using HTML, CSS, javascript, json. It is not necessary for backend to be working but the frontend should be good. App should to simple and useful in our day to day life. For eg- grocery shopping list or alarm or weather forecast or reminder.
The code to create a Search/Filter Data with Javascript or html from html page.
The code to create a Search/Filter Data with Javascript or html from html page.
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I...
JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I edit the JavaScript below so that when the calculate button is clicked the total price only shows two decimal places by using the toFixed() method? ----------------------------------------------------------------------------------------------------------- JavaScript: // Variables var tax = "tax"; // Tax percentage var taxRate = document.getElementById('tax'); // Selecting tax element // On the time of loading the DOM we are setting the tax rate window.addEventListener('DOMContentLoaded', (event) => { taxRate.value =...
Debug3-4.css You’ve been given the initial HTML and CSS code for this web page, but there...
Debug3-4.css You’ve been given the initial HTML and CSS code for this web page, but there are several errors in the CSS stylesheet. Use your knowledge of CSS to locate and fix the errors. The body element should have a width that is 90% of the width of the browser window ranging from a minimum of 600 pixels up to a maximum of 1024 pixels. Fix the syntax errors in the body style rule that defines the width of the...
suggests on how to save the web portfolio Programming languages Chosen: HTML, CSS, and JavaScript. Project...
suggests on how to save the web portfolio Programming languages Chosen: HTML, CSS, and JavaScript. Project Name: Auto Portfolio Project Goal: Create a website that will generate a web portfolio using information inputted by the user. Product Backlog using user stories: As a user, I want to be able to save my web portfolio in a format which I can save so I can use the website later for my own needs. Example: http://www-personal.umich.edu/~hamatilo/
suggests on how to save the web portfolio Programming languages Chosen: HTML, CSS, and JavaScript. Project...
suggests on how to save the web portfolio Programming languages Chosen: HTML, CSS, and JavaScript. Project Name: Auto Portfolio Project Goal: Create a website that will generate a web portfolio using information inputted by the user. Product Backlog using user stories: As a user, I want to be able to save my web portfolio in a format which I can save so I can use the website later for my own needs.
Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed....
Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed. 1. Need an HTML form and a login form; separate file. 2. need a CSS file to make it look good 3. Must store visitors' info in a .txt file and validate from there if the user exists before granting access to the dashboard. If the user does not exist, render the form to signup. If the user exists take them to their dashboard....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT