lesson2
This commit is contained in:
parent
0b5b29b339
commit
dff15c66d5
@ -337,3 +337,50 @@ bread1.bake()
|
|||||||
|
|
||||||
//Import
|
//Import
|
||||||
//import {greet} from "./greet.js";
|
//import {greet} from "./greet.js";
|
||||||
|
|
||||||
|
const chalk = require('chalk')
|
||||||
|
|
||||||
|
console.log(chalk.red('Hello World!'))
|
||||||
|
|
||||||
|
//Extra exercise
|
||||||
|
|
||||||
|
//printPyramid(5)
|
||||||
|
|
||||||
|
// Expected output
|
||||||
|
// 1
|
||||||
|
// 1 2
|
||||||
|
// 1 2 3
|
||||||
|
// 1 2 3 4
|
||||||
|
// 1 2 3 4 5
|
||||||
|
|
||||||
|
|
||||||
|
const printPyramid = (n) => {
|
||||||
|
for (let i = 1; i <= n; i++) {
|
||||||
|
let row = '';
|
||||||
|
for (let j = 1; j <= i; j++) {
|
||||||
|
row += j + ' ';
|
||||||
|
}
|
||||||
|
console.log(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printPyramid(10)
|
||||||
|
|
||||||
|
// fibonacci(8) // Expected output: 0 1 1 2 3 5 8 13
|
||||||
|
|
||||||
|
const fibonacci = (n) => {
|
||||||
|
let i = 0;
|
||||||
|
let j = 1;
|
||||||
|
|
||||||
|
console.log(i);
|
||||||
|
console.log(j);
|
||||||
|
|
||||||
|
for (let count = 2; count < n; count++) {
|
||||||
|
let next = i + j;
|
||||||
|
console.log(next);
|
||||||
|
i = j;
|
||||||
|
j = next;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fibonacci(8)
|
||||||
Loading…
x
Reference in New Issue
Block a user