-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript-functions-solo.js
179 lines (138 loc) · 5.55 KB
/
javascript-functions-solo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Write a function named marco that returns "polo".
// Pseudocode:
// create a function called marco
// return polo
// const marco = (() => {
// return "polo"
// })
// console.log(marco())
// Write a function named greeting that takes a name as an argument and returns "Welcome, <person's name here>!"
// Pseudocode
// create a function called greeting
// takes in a name as an argument
// returns "welcome, <person's name here>!"
// const greeting = ((name) => {
// return `welcome, ${name}!`
// })
// console.log(greeting("Shannon"))
// Write a function named oddOrEven that takes a number as an argument and returns whether the number is odd or even.
// Pseudocode
// create function called oddOrEven that takes a number as an argument and returns whether the number is odd or even
// input = number
// output = odd or even
// const oddOrEven = ((num1) => {
// if (num1 % 2 === 0) {
// return "even"
// } else {
// return "odd"
// }
// })
// console.log(oddOrEven(5))
// test Write a function named triple that takes a number as an argument and returns the result of that number multiplied by 3.
// Pseudocode
// create function called triple that takes a number as an argument and returns number * 3
// input = number
// output = number * 3
// const triple = ((number) => {
// return number * 3
// })
// console.log(triple(9))
// Write a function named multiply that takes two numbers as arguments and returns the result of the numbers multiplied together.
// Pseudocode
// create function called multiply that takes two numbers as arguments
// two parameters
// returns the result of the numbers multiplied together
// input = num1, num2
// output = result
// const multiply = ((num1, num2) => {
// return num1 * num2
// })
// console.log(multiply(2, 5))
// Write a function named divisibleBy that takes two numbers as arguments and returns whether the first number is evenly divisible by the second so that divisibleBy(10, 5) logs "10 is evenly divisible by 5".
// Psuedocode
// create function called divisibleBy that takes two numbers as arguments
// returns whether first number is evenly divisible by the second number
// if first number is divisible by second number, logs "num1 is divisible by num2"
// const divisibleBy = ((num1, num2) => {
// if (num1 % num2 === 0) {
// return `${num1} is divisible by ${num2}`
// }
// })
// console.log(divisibleBy(10, 5))
// Write a function named assignGrade that takes a number score as an argument and returns the letter grade for the score.
// Pseudocode
// create function called assignGrade that takes a number score as an argument and returns the letter grade for the score
// one parameter, one argument = number
// returns a string/letter
// const assignGrade = ((num1) => {
// if (num1 >= 90 && num1 <= 100) {
// return "A"
// } else if (num1 >= 80 && num1 <= 89) {
// return "B"
// } else if (num1 >= 70 && num1 <= 79) {
// return "C"
// } else {
// return "please try again"
// }
// })
// console.log(assignGrade(82))
// Write a function named isLonger that takes two strings as arguments and returns the string that contains the most characters.
// Pseudocode:
// create function called isLonger that takes in two parameters/strings
// returns the string that is longest
// const isLonger = ((string1, string2) => {
// if (string1.length > string2.length) {
// return string1
// } else if (string2.length > string1.length) {
// return string2
// }
// })
// console.log(isLonger("hello good people", "goodbye good people"))
// Write a function named greaterNum that takes two numbers as arguments and returns whichever number is the greater (higher) number.
// Pseudocode
// create function called greaterNum that takes two parameters/numbers and returns which is greater
// const greaterNum = ((num1, num2) => {
// if (num1 > num2) {
// return num1
// } else if (num2 > num1) {
// return num2
// }
// })
// console.log(greaterNum(299, 200))
// -. Write a function named yelling that takes a string as an argument and return the string in all uppercase case letters.
// const yelling = (string) => {
// return string.toUpperCase()
// }
// console.log(yelling("shannon"))
// 🏔 Stretch Goals
// The World Translator
// Write a function named helloWorld that takes a language code (e.g. "es", "de", "en") as an argument and returns "Hello World!" in the given language. Ensure you function works for at least 5 languages.
// Have your function default to returning English.
// The Pluralizer
// Pseudocode
// create function called helloWorld that takes in a language code as an argument and returns "Hello World!" in the given language
// default should return in English
// input: language code
// output: "Hello World!" in given languag
const helloWorld = ((lang) => {
if (lang == "fr") {
return 'Bonjour tout le monde!'
} else if (lang == "es") {
return 'Hola Mundo!'
} else {
return "Hello World!"
}
})
console.log(helloWorld("es"))
// Write a function named pluralizer that takes a number and a singular noun as arguments and returns the number and pluralized form of the noun, if necessary.
// Enhance your function so it can handle a few collective nouns like "sheep", "goose", "child", "person" and "species".
// pluralizer(5, "cat")
// // output: "5 cats"
// pluralizer(1, "dog")
// // output: "1 dog"
// pluralizer(9, "dog")
// // output: "9 dogs"
// pluralizer(1, "people")
// // output: "1 person"
// pluralizer(3, "people")
// // output: "3 people"