Skip to content

Commit c46e152

Browse files
committed
bonus exercise
1 parent 1d81e07 commit c46e152

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

bonus_functions.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Function bonus exercises</title>
6+
7+
</head>
8+
<body>
9+
<script src="js/bonus_functions.js"></script>
10+
</body>
11+
</html>

js/bonus_functions.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
"use strict";
2+
3+
//
4+
// Function Drills
5+
// Functions using conditionals but not loops or arrays:
6+
//
7+
// Make a function named isOdd(number)
8+
9+
function isOdd(num){
10+
return num%2 === 1;
11+
}
12+
13+
console.log(isOdd(9), 9, 'odd');
14+
console.log(isOdd(8), 8, 'odd');
15+
16+
// Make a function named isEven(number)
17+
function isEven(num){
18+
return num%2 === 0;
19+
}
20+
21+
console.log(isEven(9), 9, 'even');
22+
console.log(isEven(8), 8, 'even');
23+
24+
// Make a function named identity(input) that returns the input exactly as provided.
25+
// Make a function named isFive(input)
26+
// Make a function named addFive(input) that adds five to some input.
27+
// Make a function named isMultipleOfFive(input)
28+
// Make a function named isThree(input)
29+
// Make a function named isMultipleOfThree(input)
30+
// Make a function named isMultipleOfThreeAndFive(input)
31+
// Make a function named isMultipleOf(target, n) which checks if target is evenly divisible by n
32+
// Make a function named isTrue(boolean)
33+
// Make a function named isFalse(boolean)
34+
// Make a function named isTruthy(input), remember that values other than true will behave like true
35+
// Make a function named isFalsy(input), remember that values other than false behave like false
36+
// Make a function named isVowel(letter)
37+
// Make a function named isConsonant(letter)
38+
// Make a function named isCapital(letter)
39+
// Make a function named isLowerCase(letter)
40+
// Make a function named hasLowerCase(string) that returns if a string has any lower cased letter
41+
// Make a function named isSpace(letter) that returns if a character is a space character
42+
// Make a function named isZero(number)
43+
// Make a function named notZero(input) that returns true if the input is not zero
44+
// Write a function named lowerCase(string)
45+
// Write a function named double(n) that returns a number times two
46+
// Write a function named triple(n) that returns a number times 3
47+
// Write a function named quadruple(n) that returns a number times 4
48+
// Write a function named half(n) that returns 1/2 of the provided input
49+
// Write a function named subtract(a, b) that returns a minus b
50+
// Write a function named multiply(a, b) that returns the product of a times b
51+
// Write a function named divide(a, b) that returns a divided by b
52+
// Write a function named remainder(a, b) that returns the remainder after dividing a by b
53+
// Make a function named modulo(a, b) that returns the returns the remainder after dividing a by b
54+
// Write a function named cube(n) that returns n * n * n
55+
// Write a function named squareRoot(n) that returns the square root of the input
56+
// Write a function named cubeRoot(n) that returns the cube root of the input
57+
// Write a function named invertSign(number) that returns a negative version of a postive number, a positve version of negative, and false for all else.
58+
// Write a function named degreesToRadians(number)
59+
// Write a function named radiansToDegrees(number)
60+
// Make a function named isBlank(input) that determines if a given input is spaces, newline characters, or tabs.
61+
// Make a function named trim(string) that removes empty spaces before and after the input.
62+
// Make a function named areEqual(input1, input2) that returns if both inputs have the same value
63+
// Make a function named areIdentical(input1, input2) that returns if both inputs are same value and data type.
64+
// Make a function named not(input) returns the input with a flipped boolean
65+
// Make a function named notNot(input) that the negation of the negation of the input.
66+
// Make a function named and(predicate1, predicate2) that returns the logical operation of AND
67+
// Make a function named or(predicate1, predicate2) that returns the logical operation of OR
68+
// Write a function called reverseString(string) that reverses a string
69+
// Make a function named absoluteValue(number) that returns the absolute value of a number.
70+
// Make a function named rollDice(sides) that takes in an argument containing the number of sides the die should have. Generate a random number between 1 up to and including the number of sides.
71+
// Simple Function Drills
72+
// Make a function called returnTwo() that returns the number 2 when called
73+
// Test this function with console.log(returnTwo())
74+
//
75+
// Make a function called sayHowdy() which console.logs the string “Howdy!”
76+
//
77+
// Test this function by directly calling sayHowdy()
78+
//
79+
// Remember this function does not need a defined return value
80+
//
81+
// Make a function called returnName() that returns the string of your name
82+
//
83+
// Test this function with console.log(returnName())
84+
//
85+
// Make a function called addThree() which takes in a number input and returns the number plus 3.
86+
// Test this function with console.log(addThree(5))
87+
//
88+
// Make a function called sayString() which returns the string input passed in.
89+
// Test this function with console.log(sayString('codeup'))
90+
//
91+
// Challenge Function Drills
92+
// Write a function called identity(input) that takes in an argument called input and returns that input.
93+
//
94+
// Write a function called getRandomNumber(min, max) that returns a random number between min and max values sent to that function call.
95+
//
96+
// Write a function called first(input) that returns the first character in the provided string.
97+
//
98+
// Write a function called last(input) that returns the last character of a string
99+
//
100+
// Write a function called rest(input) that returns everything but the first character of a string.
101+
//
102+
// Write a function called reverse(input) that takes a string and returns it reversed.
103+
//
104+
// Write a function called isNumeric(input) that takes an input and returns a boolean if the input is numeric.
105+
//
106+
// Write a function called count(input) that takes in a string and returns the number of characters.
107+
//
108+
// Write a function called add(a, b) that returns the sum of a and b
109+
//
110+
// Write a function called subtract(a, b) that return the difference between the two inputs.
111+
//
112+
// Write multiply(a, b) function that returns the product
113+
//
114+
// Write a divide(numerator, denominator) function that returns a divided by b
115+
//
116+
// Write a remainder(number, divisor) function that returns the remainder left over when dividing number by the divisor
117+
//
118+
// Write the function square(a) that takes in a number and returns the number multiplied by itself.
119+
//
120+
// Write a function called sumOfSquares(a, b) that uses only your add() function and your square function and not + or * operators
121+
//
122+
// Write a function called doMath(operator, a, b) that takes 3 parameters. The first parameter is the name of the math function you want to apply. a and b are the two numbers to run that function on.
123+
//
124+
// Even More Function Bonuses
125+
// Create a function that will return how many whitespace characters are at the beginning and end of a string.
126+
//
127+
// Create a function that takes in two string inputs.
128+
//
129+
// If the second string input is present in the first, return the first input string with the second input string removed from it.
130+
// If the second string input is present multiple times in the first, the second string will only be removed where it first occurs in the first string.
131+
// If the second string input is not present in the first, return the first string as entered in the function.
132+
// Create a function that takes in a string and returns true if the last letter is an "a" (otherwise, return false).
133+
//
134+
// EXTRA CHALLENGE: create a function that will return how many whitespace characters are at the beginning of a string (hint: use regex).
135+
//
136+
// Create a function returnTrueMessage() that returns the string "Hey, it's true!"
137+
//
138+
// Create a function returnFalseMessage() that returns the string "Hey, it's false!"
139+
// Create a function returnMessage() that takes in a function and returns the call to the function
140+
// Experiement passing in different functions.
141+
// Create a function, willLoginUser() that takes in a username string, password string, user age, a boolean indicating if they are an admin.
142+
//
143+
// The function will return true if the username is not the same as the password and the user is at least 18 years old. If the user is an admin, they do not have to be a certain age but the password must still not match the username.

0 commit comments

Comments
 (0)