js using recursion to create a range of numbers

in this we will create a function that calls its self to add to an array a range of numbers

Demo

CSS

* {
  box-sizing: border-box;
  transition: all 0.2s;
  scroll-behavior: smooth;
}

JS


/***************************************/
        Not Finished - 25.11.19
/***************************************/

function run_function() {
  var my_result = "A Result";
  write_result(my_result);
  return my_result;
}

function rangeOfNumbers(startNum, endNum) {
  if(endNum === startNum) {
    return [endNum];
  } else {
    var numbers = rangeOfNumbers(startNum - 1);
    numbers.push(startNum);
    return numbers;
  }
};

// this is a common function just to write the content into the result div
function write_result(result) {
  var result_html = document.getElementById("result");
  result_html.innerHTML = result;
}

HTML

<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='run_function();' class='btn btn-primary mb-1'>Run Function</button>

Working Result

..

External Link for js using recursion to create a range of numbers

Other Items in javascript
Page Views

This page has been viewed 50 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹