jeudi 6 février 2020

how to output the minimum value from array on the website

i have the input values and js creates the array. I need that all values should be sorted by values and output the min value on the web page. User should see smth like this: the subject where u get (3(for example)) should be improved in next few days. please guys!

document.querySelector('button').addEventListener('click', function(e) {
  var inputs = document.querySelectorAll('input');    

  var obj = [].reduce.call(inputs, (accumulator, currentValue, currentIndex) => {
    accumulator[`val${currentIndex}`] = currentValue.value
    return accumulator
  }, {})
  
  console.log(obj)
});
<form>
    <table id="tblSearchTally">
        <tr>
            <td>Biology:<input type= "text" ></td>     
        </tr>
        <tr>
            <td>Chemistry:<input type= "text" ></td>      </tr>
        <tr>
            <td>Physics:<input type= "text" ></td>      </tr>
        <tr>
            <td>Math:<input type= "text" ></td>     
        </tr>
  
    </table>
  <button type="button">Go</button>
</form>



Aucun commentaire:

Enregistrer un commentaire