JSFiddle - React, Tailwind, and code Playground

by Ty

HTML

<!DOCTYPE>
<html>
	<head>
		<title>Exercise 2</title>
		<script type="text/javascript" src="js/loops.js">
		
		
		</script>
		
	</head>
		
		
		<body>
		
		
		<button onclick="printFibonacciList()">printFibonacciList</button>

		
		</body>
		

</html>

JavaScript

function printFibonacciList(fibCount) {
var fibCount = window.prompt("How many numbers do you need?");

var num0 = 0;
var num1 = 1;
var result ='0,1';

for (i=0; i< fibCount-2; i++){
	var current = num0 + num1;
		result = result + ',' + current;
		num0 = num1;
		num1 = current;
    
}

while (i < (fibCount - 2)) {
var current = num0 + num1;
    result = result + "," + current;
    num0 = num1;
    num1 = current;	
    i++;



}
console.log(result);
}