From 63ab483c05233551406978613a6a4bc0cfd0d381 Mon Sep 17 00:00:00 2001 From: Youssef Khedher Date: Wed, 9 Oct 2019 22:15:31 +0100 Subject: [PATCH] Factoriel program written in JavaScript --- factoriel.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 factoriel.js diff --git a/factoriel.js b/factoriel.js new file mode 100644 index 0000000..b1ad64f --- /dev/null +++ b/factoriel.js @@ -0,0 +1,22 @@ +const readline = require('readline'); +const factoriel = a => { + if(a != 0) + { + var res = a * factoriel(a-1) + } + if(a === 1) + { + return 1; + } + return res; +} + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +rl.question('Enter a number: ', (number) => { + console.log(`The factoriel of ${number} is ${factoriel(number)}`); + rl.close(); +});