From dff15c66d5a61ec9ac3cc7081e5a7a0f12bf14a9 Mon Sep 17 00:00:00 2001 From: tuffahni Date: Wed, 18 Dec 2024 19:45:34 +0000 Subject: [PATCH] lesson2 --- nodeJS/Learning/01/index.js | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/nodeJS/Learning/01/index.js b/nodeJS/Learning/01/index.js index b8d5446..924f4e3 100644 --- a/nodeJS/Learning/01/index.js +++ b/nodeJS/Learning/01/index.js @@ -336,4 +336,51 @@ bread1.bake() // Modules: it only happens in a modules //Import -//import {greet} from "./greet.js"; \ No newline at end of file +//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) \ No newline at end of file