Last active
November 3, 2017 16:21
-
-
Save dyee00/df0a083be7e551da54fd470673973503 to your computer and use it in GitHub Desktop.
JS Project 1
This file contains 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
// JS Project #1 | |
// Group 1 - Data | |
// HUBOT_SLACK_TOKEN=xoxb-254477195828-yKXenoY5BXI6pZibTVlrhbxr ./bin/hubot --adapter slack | |
*************************** READ ME ****************************************** | |
******************************************************************************** | |
#1 - Random yo momma jokes | |
Description: Hubot will tell a random "yo momma" joke when prompted. | |
Instructions: Ask @Data the following questions to generate a response: | |
Type: Tell me a yo momma joke | |
This will return a response of a random "yo momma" joke based on an array of 6 jokes. | |
******************************************************************************** | |
#2 - World's Top 25 Most Livable Cities | |
Description: Hubot will list the top 25 livable cities around the world based on Monocle magazine's Quality of Life Survey of 2017. | |
Instructions: Ask @Data the following questions to generate a response: | |
Type: Where are the world's most livable cities for 2017? | |
This will return a response with a list of the 25 cities based on an array as well as a link to a video explanation of the ranking. | |
Type(any of questions below): | |
Are there any cities from Asia? | |
Are there any cities from Europe? | |
Are there any cities from Australia? | |
Are there any cities from North America? | |
Are there any cities from South America? | |
Are there any cities from Africa? | |
Are there any cities from Antartica? | |
This will return a response listing all the cities from the list according to their location by continents. | |
This is retrieved from an array and uses array.length. | |
******************************************************************************** | |
#3 - Rock, Paper, Scissors Game | |
Description: Challenge @Data to a game of rock, paper, scissors. | |
Instructions: Ask Hubot the following items below to play a game of rock, paper, scissors: | |
Type: Let's play rock, paper, scissors | |
This will return a response as well as the instructions for the game | |
Type: I choose ____ | |
Type either rock, paper or scissors after the phrase "I choose " and this will | |
return a response of what @Data has chosen and will also declare a winner. | |
@Data's choices are based on a math.random code, the messages returned are based | |
on if/else statements. | |
*************************** READ ME END ****************************************** | |
// ******************************************************************************** | |
// ******************************************************************************** | |
// ******************************************************************************** | |
// Code Starts below | |
// ******************************************************************************** | |
module.exports = function(bot) { | |
// #1 - "Random yo momma jokes" - start | |
bot.hear(/Tell me a yo momma joke/i, function(res) { | |
var randomJoke = function () { //randomJoke function starts | |
var jokes = [ | |
"Yo momma is so fat when she got on the scale it said, \"I need your weight not your phone number.\"", | |
"Yo momma is so fat she takes selfies in panoramic mode.", | |
"Yo momma is so stupid she brought a spoon to the super bowl.", | |
"Yo momma is so dumb that it takes her 2 hours to watch 60 Minutes.", | |
"Yo momma is so ugly, her portraits hang themselves.", | |
"Yo momma is so ugly, when she threw a boomerang, it wouldn't come back." | |
]; | |
var yoMomma = jokes[Math.floor(Math.random() * jokes.length)]; | |
return yoMomma; | |
}; //randomJoke function ends | |
return res.send("Here's one - " + randomJoke() ); | |
}); // end - random yo momma jokes | |
// ******************************************************************************** | |
// #2 - World’s Top 25 Most Livable Cities for 2017 | |
var cities = ["1. Tokyo", "2. Vienna", "3. Berlin", | |
"4. Munich","5. Melbourne","6. Copenhagen", | |
"7. Sydney", "8. Zürich", "9. Hamburg", "10. Madrid", | |
"11. Stockholm", "12. Kyoto", "13. Helsinki", "14. Fukuoka", | |
"15. Hong Kong", "16. Lisbon", "17. Barcelona", "18. Vancouver", | |
"19. Dusseldorf", "20. Amsterdam", "21. Singapore", | |
"22. Auckland", "23. Brisbane", "24. Portland", "25. Oslo"]; | |
var citiesString = cities.join(', '); | |
var asia = ["Tokyo", "Kyoto", "Fukuoka", "Hong Kong", "Singapore" ]; | |
var asiaString = asia.join(', '); | |
var asiaLength = asia.length; | |
var australia = ["Melbourne", "Sydney", "Auckland", "Brisbane" ]; | |
var australiaString = australia.join(', '); | |
var australiaLength = australia.length; | |
var europe = ["Vienna", "Berlin", "Munich", "Copenhagen", "Zürich", "Hamburg", | |
"Madrid", "Stockholm", "Helsinki", "Lisbon", "Barcelona", "Dusseldorf", | |
"Amsterdam", "Oslo" ]; | |
var europeString = europe.join(', '); | |
var europeLength = europe.length; | |
var northAmerica = ["Vancouver", "Portland"]; | |
var northAmericaString = northAmerica.join(', '); | |
var northAmericaLength = northAmerica.length; | |
var none = ["none listed", "0"]; | |
var logo = "https://i.pinimg.com/736x/0d/80/e8/0d80e89b2aa4f3ee93f0aeec01dfc60d--monocle-magazine-logo-type.jpg"; | |
// var vidLink = "https://vimeo.com/223486210"; | |
var vidLink = "https://monocle.com/film/affairs/quality-of-life-survey-top-25-cities-2017/"; | |
bot.hear(/Where are the world's most livable cities for 2017?/i, function(res) { | |
return res.reply("According to Monocle magazine's Quality of Life Survey of 2017, the \"World's Most Liveable Cities of 2017\" are: " | |
+ "\n" + logo + "\n" + citiesString + "\n" + "\n" + | |
"For additional information, please view the video below: " + "\n" + vidLink); | |
}); | |
bot.hear(/Are there any cities from Asia?/i, function(res) { | |
return res.reply("There are " + asiaLength + " cities from Asia. " + "\n" + "They are - " + asiaString); | |
}); | |
bot.hear(/Are there any cities from Europe?/i, function(res) { | |
return res.reply("There are " + europeLength + " cities from Europe. " + "\n" + "They are - " + europeString); | |
}); | |
bot.hear(/Are there any cities from Australia?/i, function(res) { | |
return res.reply("There are " + australiaLength + " cities from Australia. " + "\n" + "They are - " + australiaString); | |
}); | |
bot.hear(/Are there any cities from North America?/i, function(res) { | |
return res.reply("There are " + northAmericaLength + " cities from North America. " + "\n" + "They are - " + northAmericaString); | |
}); | |
bot.hear(/Are there any cities from South America?/i, function(res) { | |
return res.reply("There are " + none[1] + " cities from South America. " + "\n" + "They are - " + none[0]); | |
}); | |
bot.hear(/Are there any cities from Africa?/i, function(res) { | |
return res.reply("There are " + none[1] + " cities from Africa. " + "\n" + "They are - " + none[0]); | |
}); | |
bot.hear(/Are there any cities from Antartica?/i, function(res) { | |
return res.reply("There are " + none[1] + " cities from Antartica. " + "\n" + "They are - " + none[0]); | |
}); | |
// end - World’s Top 25 Most Liveable Cities for 2017 | |
// ******************************************************************************** | |
// #3 - "Rock, Paper, Scissors Game" start | |
bot.hear(/Let's play rock, paper, scissors/i, function(res){ // RPS game starts | |
return res.send("Ok, it's on! " + "\n" + "\n" + | |
"Instructions: start by typing the following message: " + "\n" + "\n" + | |
" \"I choose\" followed by either \"rock\", \"paper\" or \"scissors\" (without the quotes) " + | |
"and I will reveal what I chose as well as declare a winner."); | |
}); | |
bot.hear(/I choose (.*)/i, function(msg) { | |
var user; | |
user = msg.match[1]; | |
var computerChoice = Math.random(); | |
if (computerChoice < 0.34) { | |
computerChoice = "rock"; | |
} else if(computerChoice <= 0.67) { | |
computerChoice = "paper"; | |
} else { | |
computerChoice = "scissors"; | |
} console.log("Computer: " + computerChoice); | |
// var choices = ["rock", "paper", "scissors"]; | |
// var computerChoice = function() { | |
// choices[Math.floor(Math.random() * choices.length)]; | |
// return(computerChoice); | |
// } | |
var tieMsg = "The result is a tie!"; | |
var rockMsg = "Result: Rock wins!"; | |
var paperMsg = "Result: Paper wins!"; | |
var scissorsMsg = "Result: Scissors wins!"; | |
var errorMsg = "Invalid!!! Please select either rock, paper or scissors"; | |
var game = function(choice1, choice2) { | |
if (choice1 === choice2) { | |
return(tieMsg); | |
} | |
if (choice1 === "rock") { | |
if(choice2 ==="scissors") { | |
return(rockMsg); | |
} else { | |
return(paperMsg); | |
} | |
} | |
if (choice1 === "paper") { | |
if(choice2 ==="rock") { | |
return(paperMsg); | |
} else { | |
return(scissorsMsg); | |
} | |
} | |
if (choice1 === "scissors") { | |
if (choice2 === "rock") { | |
return(rockMsg); | |
} else { | |
return(scissorsMsg); | |
} | |
} | |
if (choice1 !== "rock" || "paper" || "scissors") { | |
return(errorMsg); | |
} | |
}; | |
return msg.send("Data chose " + computerChoice + "\n" + "\n" + game(user, computerChoice)); | |
}); // end - Rock, Paper, Scissors Game | |
}; // end - module.exports funciton |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overall Thoughts
I would've done something like this.
Rating
4/4
Let me know if you have any question or you're welcome to come to my office hours.
Best,
Stephen