Created
April 6, 2022 12:14
-
-
Save Hegabovic/a46e8dde830373fd2e6f3a360800c6db to your computer and use it in GitHub Desktop.
NodeJS: downloading NodeJS and exporting modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let calc = require("./calcMethod"); | |
let personalData = require("./personData") | |
// <------------- demo 1 -----------------> // | |
console.log(calc.math("A",1,calc.add)); | |
console.log(calc.math(1,3,calc.subtract)); | |
console.log(calc.math(1,3,calc.multiply)); | |
// <------------- demo 2 -----------------> // | |
console.log(personalData("Hegabovic",1995)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using function callback | |
let add = function add(num1, num2) { | |
return num1 + num2; | |
} | |
let subtract = function subtract(num1, num2) { | |
return num1 - num2; | |
} | |
let multiply = function multiply(num1, num2) { | |
return num1 * num2; | |
} | |
let math = function math(num1, num2, func) { | |
if( isNaN(num1) || isNaN(num2) ){ | |
return "please enter a valid number"; | |
}else { | |
return func(num1, num2); | |
} | |
} | |
module.exports = { | |
add, | |
subtract, | |
multiply, | |
math | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let personDate = function personData(name, date) { | |
let currentYear = new Date(); | |
currentYear.getFullYear() | |
if (isNaN(name)) { | |
let age = currentYear.getFullYear() - date; | |
return `Hello ${name} and your age now ${age}`; | |
} | |
} | |
// console.log(personData("Hegabovic",1995)) | |
module.exports = personDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment