Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created July 9, 2013 18:02
Show Gist options
  • Save burtlo/5959656 to your computer and use it in GitHub Desktop.
Save burtlo/5959656 to your computer and use it in GitHub Desktop.
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