Skip to content

Instantly share code, notes, and snippets.

/*
NICKNAME GENERATOR
Write a naive nickname generator function that takes a name and returns the first 3 or 4 letters (4 letters if the 3rd is a vowel)
eg nickName("daniel") ==> 'dan'
nickName("Beowulf") ==> 'Beow'
*/
function nickName(name) {
/*
SEASONS OF LOVE
Complete the function so it generates the numbers of minutes in a year and logs that number to the console.
*/
var seasonsOfLove = function() {
var minutesInDay = 60*24;
var daysInYear = 365;
return minutesInDay * daysInYear;
/*
ROUND TOWN
We will look at 3 Math functions in some depth:
Math.floor(x)
Math.ceil(x)
Math.round(x)
Math.floor() returns the largest integer less than or equal to a given number.
ex)
/*
OPEN SESAME
Our gate function is not very secure. Choose a password from the passwords array (or write your own and add it to the array). Then, uncomment and complete the if statement and foor loop so the gate only logs an entry message when the designated password is selected by the loop
*/
var passwords = [
'Password123',
/*
UP & DOWN
Create a function countUpThenDown() that takes a number n and logs all the numbers 0 to n and back to 0.
eg)
countUpThenDown(2) ==> 0 1 2 1 0
countUpThenDown(11) ==> 0 1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1 0
*/
/*
HOLY CRAPS
We're creating a simplified verison of the popular casino game craps.
A player rolls 2 dice. If the total of those dice is 7 or 11, the player wins,
otherwise he or she must add more money to the betting pool and roll again
Complete the while loop and run your code to play some craps!
*/
/*
Thoughtful Thursdays - RPS
*/
function rockPaperScissors(hand1, hand2) {
// hand1 equals hand2, return 'tie'
if (hand1 === hand2) {
return 'TIE';
}
/*
NAME GAMES
Create two functions, sayMyName() and playNameGame()
sayMyName() will take 2 arguments: a first name and a last name. It will log out the string "My name is FIRSTNAME LASTNAME"
sayMyName("Dan", "The Man") ==> "My name is Dan The Man"
playNameGame() will take a person's first name. It will log out a string of the name game song
/*
BLOOD ALCOHOL CALC
An individual's BAC may be calculated as follows:
BAC% = (A × 5.14 / W × r) - 0.15 × H
A: Total alcohol consumed, in ounces (oz)
W: Body weight, in pounds (lbs)
r: The alcohol distribution ratio, 0.73 for man, and 0.66 for women
H: Time passed since drinking, in hours
//Complete properNounFilter()
// The function should return true if the word argument is a proper Noun (first letter is capitalized). It should return false if the word isn't a proper Noun, if the word is mixed case or if it is all caps
var properNounFilter = function(word) {
var firstLetter = word.slice(0,1);
var remainder = word.slice(1);
if (firstLetter.toUpperCase() === firstLetter && remainder.toLowerCase() === remainder) return true;
return false;
}