30
loading...
This website collects cookies to deliver better user experience
The act of a function calling itself, recursion is used to solve problems that contain smaller sub-problems. A recursive function can receive two inputs: a base case (ends recursion) or a recursive case (resumes recursion).
function recursiveFunction(num){
if (num < 10) {
console.log(`Number = ${num}. recursiveFunction will be called.`)
recursiveFunction(num+1)
} else {
console.log(`Number = ${num}. Recursion terminated.`)
}
}
function randomLyric(array) {
let random = array[Math.floor(Math.random()*array.length)];
if (lyric !== random) {
setLyric(random);
} else {
randomLyric(array)
}
}