- Joined
- Sep 12, 2022
- Messages
- 39
- Reaction score
- 0
I believe, the code is correct, the issue is with the output to a web browser. What's the fix?
JavaScript:
function countdown(n){
if (n < 1) {
return document.getElementById("recursivep").innerHTML = [];
} else {
let firstarr = countdown(n - 1);
firstarr.unshift(n);
return document.getElementById("recursivep").innerHTML = firstarr;
}
}
HTML:
<!DOCTYPE html>
<html>
<head>
<script async src="Recursive function.js"></script>
</head>
<body>
<main>
<div>
Recursive function
<button onclick="countdown()">click me</button>
<p id="recursivep"></p>
</div>
</main>
</body>
</html>