-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdl.js
46 lines (44 loc) · 1.49 KB
/
mdl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var events = require('events');
var util = require('util');
util.inherits(Hotel, events.EventEmitter);
function Hotel(){//creates a variable scope
this.data = {//Will holds a basic info for each hotel
hotel_name: null,
hotel_industry: null,
hotelGrade: null ,
};
events.EventEmitter.call(this);
this.setAllData = function(info) {
for (var i in this.data) {
this.data[i]= info[i];
}
};
var log;//variable that will hold all print logs
this.addLike = function(counter) {
this.data.hotelGrade += counter;
this.emit('rankChanged');// fire event
}
this.UnLike = function(counter) {
this.data.hotelGrade -= counter;
this.emit('rankChanged');// fire event
}
this.displayRank = function (){
if(this.data.hotelGrade<0) { //checks if grate<0
console.log("Invalid rating: " + this.data.hotelGrade);
this.log+="Invalid rating: " + this.data.hotelGrade + "\n";
}
else{ //if grate>=0
console.log("Hotel: "+this.data.hotel_name+ " - " +this.data.hotel_industry+ ", the rank is: " + this.data.hotelGrade);
this.log+="Hotel: "+this.data.hotel_name+ " - " +this.data.hotel_industry+ ", the rank is: " + this.data.hotelGrade + "\n";
}
}
this.returnLog = function() //log function
{
return this.log;
}
};
module.exports = function(info) {
var newHotel = new Hotel(); //creates instance
newHotel.setAllData(info);
return newHotel;
};