Skip to content

Instantly share code, notes, and snippets.

@Hegabovic
Created April 6, 2022 12:14
Show Gist options
  • Save Hegabovic/a46e8dde830373fd2e6f3a360800c6db to your computer and use it in GitHub Desktop.
Save Hegabovic/a46e8dde830373fd2e6f3a360800c6db to your computer and use it in GitHub Desktop.
NodeJS: downloading NodeJS and exporting modules
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));
// 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
}
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