Array in javaScript and for loop?

  • 0
    Hello
    There is an array of 1 and 2, in 1 he pushed 15 dollars, in 2 - 19 dollars, if a person enters 1 in the input, then the CYCLE must how to go over the value in the array and output (for example, to the console) 15 $ or 19 $ if he enters 2
    How to do it? ) thanks for earlier.

    var weight;
    
    var a = []
    a[1] = "15.00$"
    a[2] = "19.00$"
    
    function getData() {
      weight = document.getElementById("weight").value;
      for(тут надо залесть в var a[]) {
        а тут вывести значение, если вес 1 то 15$, если 2 то 19$
      }
    }


    <input type="number" id="weight" value="1">
    <button onclick="getData()" type="button">Click</button>
    JavaScript Gideon Knox, Apr 26, 2019

  • 1 Answers
  • 0
    So?

    Isaiah Leonard

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!