Skip to content

Instantly share code, notes, and snippets.

@ceme
Created May 6, 2013 23:02
Show Gist options
  • Save ceme/5528967 to your computer and use it in GitHub Desktop.
Save ceme/5528967 to your computer and use it in GitHub Desktop.
fibonacci in js and html5 and jQuery
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>fibonacci</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<div id="content"></div>
<script>
function Fibonacci() {
var series = [];
this.series = series;
};
Fibonacci.prototype.createSet = function(length) {
for (i = 0; i < length; i++){
if (i==0) {
this.series[i] = 0;
} else if (i==1) {
this.series[i] = 1;
} else {
var n = this.series[i-1] + this.series[i-2];
this.series[i] = n;
}
}
};
var x = new Fibonacci();
x.createSet(30);
console.log(x.series);
$("#content").append(x.series.join(' : '));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment