Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scoreToHTML(inputArr) {
- let result = "<table>\n";
- result += " <tr><th>name</th><th>score</th></tr>\n";
- for (let line of inputArr) {
- result += ` <tr><td>${escapeHTML(line.name)}</td><td>${+line.score}</td></tr>\n`;
- }
- result += "</table>";
- console.log(result);
- function escapeHTML(str) {
- "use strict";
- str = str.replace(/&/g, "&")
- .replace(/>/g, ">")
- .replace(/</g, "<")
- .replace(/"/g, """)
- .replace(/'/g, "'");
- return str;
- }
- }
- //Uslovie
- // 2. Score to HTML
- // You are given a JSON string representing an array of objects, parse the JSON and create a table using the supplied objects. The table should have 2 columns "name" and "score", each object in the array will also have these keys.
- // Any text elements must also be escaped in order to ensure no dangerous code can be passed.
- // You can either write the HTML escape function yourself or use the one from the Strings and Regular Expressions Lab.
- // The input comes as a single string argument – the array of objects as a JSON.
- // The output should be printed on the console – a table with 2 columns - "name" and "score", containing the values from the objects as rows.
- // Input
- // '[{"name":"Pesho","score":479},{"name":"Gosho","score":205}]'
- // Output
- // <table>
- // <tr><th>name</th><th>score</th></tr>
- // <tr><td>Pesho</td><td>479</td></tr>
- // <tr><td>Gosho</td><td>205</td></tr>
- // </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement