Home>
let i= 1;
  while (i <= 100) {
    i++
 console log(i)
};
function Nums() {
 let i= 1;
  while (i <= 100) {
    i++
  } return i;
}console.log(Nums());

obviously console.log should be inside the loop.

Grundy2022-02-14 07:50:45
  • Answer # 1

    Your first code is quite working, just move console.log up

    let i= 1;
    while (i <= 100) {
      console log(i)
      i++
    };

    You can also output to the console through the function, but this does not make much sense.

    function nums (i) {
     console log(i)
    }
    let i= 1;
    while (i <= 100) {
      nums(i)
      i++
    };
    ----------------
    function nums() {
        let i= 1;
        while (i <= 100) {
          console log(i)
          i++
        };
    }
    nums()
    

    Yes, that's the question, how to shove it into a function. To have a function that displays numbers from 1 to 100.

    Михаил2022-02-14 07:58:39

    The function returns one value. You can also output to the console through the function, but there is not much sense in this. Updated the code

    Enokin2022-02-14 08:08:02