Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
elcymon committed Jun 15, 2018
1 parent dac9907 commit 110f06b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 54 deletions.
50 changes: 5 additions & 45 deletions mine-practice/app.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
//#6 Modules and require
//for dividing code into logical modules i.e. separate files.
//our applications can be divided into logical files.
//#7
var stuff = require('./stuff');//what is exported is returned and stored in counter variable.

var counter = require('./count');//what is exported is returned and stored in counter variable.

console.log(counter(['shaun','crystal','ryu']));
//#4
// var time = 0;
// var timer = setInterval(function(){
// time += 2;
// console.log(time + ' seconds have passed');
// if (time > 5){
// clearInterval(timer);
// }
// },2000);


// console.log(__dirname);
// console.log(__filename);


//#5 Function Expressions
function callFunction(fun){
fun();
}
//normal function statement

function sayHi(){
console.log('Hi');
}

sayHi();

//function expression is assigning a variable to an anonymous function

var sayBye = function(){
console.log('bye');

};

sayBye();

callFunction(sayBye);

callFunction(sayHi);
console.log(stuff.counter(['shaun','crystal','ryu']));
console.log(stuff.adder(4,5));
console.log(stuff.adder(stuff.pi,5));
9 changes: 0 additions & 9 deletions mine-practice/count.js

This file was deleted.

34 changes: 34 additions & 0 deletions mine-practice/stuff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var counter = function(arr){
return 'There are ' + arr.length + ' elements in this array';
};
var adder = function(a,b){
return `The sum of the 2 numbers is ${a+b}`;
};

var pi = 3.142;
// //need to explicitly say what part of this module we want available outside this module
// //module.exports is an empty object, which we can use dot notation to add properties to it

module.exports.counter = counter;
module.exports.adder = adder;
module.exports.pi = pi;

// console.log(counter(['shaun','crystal','ryu']));

//ANOTHER WAY IS TO ASSIGN THE VALUES/FUNCTIONS TO MODULE.EXPORTS.PROPERTIES

// module.exports.counter = function(arr){
// return 'There are ' + arr.length + ' elements in this array';
// };
// module.exports.adder = function(a,b){
// return `The sum of the 2 numbers is ${a+b}`;
// };

// module.exports.pi = 3.142;

//A THIRD APPROACH IS TO ASSIGN MODULE.EXPORTS TO A JAVASCRIPT OBJECT
// module.exports = {
// counter: counter,
// adder: adder,
// pi: pi
};

0 comments on commit 110f06b

Please sign in to comment.