+ 2

Help! Reduce code

How i do it right? var num0 = document.getElementById("num0").value*1; var num2 = document.getElementById("num2").value*1; var num1 = document.getElementById("num1").value*1; var num3 = document.getElementById("num3").value*1; var i = 0; while (i<4) { var [`num${i}`] = document.getElementById(`num${i++}`).value*1;] }

23rd Jun 2019, 1:41 AM
Miguel Perez
Miguel Perez - avatar
2 Respostas
+ 7
// look at this var num0 = document.getElementById("num0").value*1; var num2 = document.getElementById("num2").value*1; var num1 = document.getElementById("num1").value*1; var num3 = document.getElementById("num3").value*1; let nums = [num0, num1, num2, num3]; var i = 0; while (i<4) { nums[i] = document.getElementById(`num${i++}`).value*1; //cannot understand what do you want here }
23rd Jun 2019, 2:40 AM
Ayan Fox
Ayan Fox - avatar
+ 2
Thanks, i was thought it too, but i wanted not use arrays. I want to optimize my code: https://www.sololearn.com/post/114558/?ref=app
23rd Jun 2019, 2:45 AM
Miguel Perez
Miguel Perez - avatar