Created
July 9, 2013 18:02
-
-
Save burtlo/5959656 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
BobController = function(button,inputText,output) { | |
console.log("Setting up the Bob Controller"); | |
this.button = $(button); | |
this.input = $(inputText); | |
this.output = $(output); | |
var that = this; | |
this.getStatement = function() { | |
return this.input.val(); | |
} | |
this.appendResponse = function(response) { | |
var outputResponse = "<li>" + response + "</li>"; | |
this.output.append(outputResponse); | |
} | |
this.button.on("click",function(e) { | |
e.preventDefault(); | |
var bob = new Bob(); | |
var response = bob.hey(that.getStatement()); | |
that.appendResponse(response); | |
}); | |
}; | |
Bob = function() { | |
this.hey = function(message) { | |
if (this.isSilence(message)) { | |
return "Fine, be that way."; | |
} else if (this.isShouting(message)) { | |
return "Woah, chill out!"; | |
} else if (this.isAQuestion(message)) { | |
return "Sure"; | |
} else { | |
return 'Whatever'; | |
} | |
}; | |
this.isSilence = function(message) { | |
return message === ""; | |
} | |
this.isShouting = function(message) { | |
return message.toUpperCase() === message; | |
} | |
this.isAQuestion = function(message) { | |
return message[message.length -1] === "?"; | |
} | |
}; | |
$(function() { | |
var bobController = new BobController('#askBob','#askBobText','#bobResponses'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment