0

[HTML] help me please with editing array

Hi, so in my application i have created a sortable array. i want the user to be able to enter 2 values in miles and then the range of values should be added to the array and for each value the equivalent value in KM should be next to it. below is a snippet of my code but when i click the "begin conversion" button, nothing is added to the array. what am i doing wrong here? <script> var myArray = [{ 'Miles': '1', 'KM': '1.609' }, { 'Miles': '2', 'KM': '3.218' }, { 'Miles': '3', 'KM': '4.827' }, { 'Miles': '4', 'KM': '6.436' }, { 'Miles': '5', 'KM': '8.054' }, { 'Miles': '6', 'KM': '9.654' }, ] $('th').on('click', function() { var column = $(this).data('column') var order = $(this).data('order') var text = $(this).html() text = text.substring(0, text.length - 1) if (order == 'desc') { $(this).data('order', "asc") myArray = myArray.sort((a, b) => a[column] > b[column] ? 1 : -1) text += '&#9660' } else { $(this).data('order', "desc") myArray = myArray.sort((a, b) => a[column] < b[column] ? 1 : -1) text += '&#9650' } $(this).html(text) buildTable(myArray) }) buildTable(myArray) function buildTable(data) { var table = document.getElementById('myTable') table.innerHTML = '' for (var i = 0; i < data.length; i++) { var row = `<tr> <td>${data[i].Miles}</td> <td>${data[i].KM}</td> </tr>` table.innerHTML += row } } function Calculate() {

12th Feb 2020, 9:34 AM
Wavey' Babz
Wavey' Babz - avatar
1 Odpowiedź
0
Wavey' Babz Your code is too big, it doesn't fit in the Description input, and as you can see, it is getting truncated from surpassing the character limits. For future reference, always share code links instead of raw text for codes having more than 10-15 lines, to avoid similar incidents 👍 Please remove the code (as raw text) from the question Description, then follow these steps: * Create a new Web code in Code Playground. * Paste your script in the JS pane, remove the <script> and </script> tags). * Save the code. * Still within the editor, tap on the Share button on top right corner, and choose "Copy to clipboard" * Get back here, then edit the question. Paste the link within the Description input. https://www.sololearn.com/post/74857/?ref=app
12th Feb 2020, 10:03 AM
Ipang