<!DOCTYPE html
>
<
html
lang=
"en"
>
<
head
>
<
meta
charset=
"UTF-8"
>
<
meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<
meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<
title
>Document
</
title
>
</
head
>
<
body
>
</
body
>
<
script
>
// 1封装函数
function
leng(
num){
var
a=
0;
var
b=
1;
var
c=[
0,
1];
for (
let
i =
0;
c.
length <
num;
i++) {
[
a,
b]=[
b,
a+
b];
c.
push(
b)
}
return
c;
}
// 2调用函数
var
d=
leng(
7);
console.
log(
d);
//[0, 1,1, 2, 3, 5, 8, 13]
<
/
script
>
</
html
>