0

I have been trying to understand this task for school but I can't wrap my head around it. The program should display the range using a while loop (not a for loop), starting at the user input "Starting Point", and continuing until the user input "Limit" is reached. Each number is incremented by the amount that that user specifies in the "Increment" input.

Thank you!

function button() {

  let count = document.getElementById('startingPoint').value;
  let limit = document.getElementById('limit').value;
  let step = document.getElementById('increment').value;

  while (count <= limit) {
    document.getElementById('output').innerHTML += count + ' ';
    count += step;
  }
}
<body>
  <!-- Ask user for three inputs -->
  <input id="startingPoint" type="number" placeholder="Starting Point" />
  <br />

  <input id="limit" type="number" placeholder="Limit" /> <br />

  <input id="increment" type="number" placeholder="Increment" /> <br />

  <!-- Button to initiate function -->
  <br />
  <button onclick="button()">Display</button>
  <br />

  <!-- Container for output(s) -->
  <div id="output"></div>
</body>
isherwood
  • 58,414
  • 16
  • 114
  • 157
darragh
  • 11
  • 4
  • 1
    @charlietfl You should post your answer as an answer so they can mark this as solved. – Domino Feb 09 '22 at 17:21
  • There's probably a better duplicate to be found, but the gist is that input values are always strings. You need to convert. – isherwood Feb 09 '22 at 17:35

0 Answers0