-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_exercises.html
More file actions
38 lines (37 loc) · 1.54 KB
/
mini_exercises.html
File metadata and controls
38 lines (37 loc) · 1.54 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
// ================ !! Mini-exercises !!
// Write a function, returnFive, that returns the number five. No inputs should be defined.
function returnFive(input){
return 5;
}
// Write a function, isFive, that takes in an input and returns the boolean value true if the passed argument is the number 5 or the string "5". Return false otherwise.
function isFive(input) {
return input == 5
}
// Write a function, isShortWord, that takes in a string and returns the boolean value true if the passed argument is shorter than 5 characters. Return false otherwise.
function isShortWord(str) {
return str.length < 5;
}
console.log(isShortWord('sandwhich'), false)
console.log(isShortWord('four'), true)
// Write a function, isSameLength, that takes in two string inputs and returns the boolean value true if the passed arguments are the same length. Return false otherwise.
function isSameLength(string, str) {
return string.length === str.length
}
console.log(isSameLength('bear', 'griaffe'))
// Write a function, getSmallerSegment, that takes in a string and a number input. The function should return a substring of the first argument that is as many characters long as the second argument in lowercase.
function getSmallerSegment(stri, segmentLength){
return stri.substring(0, segmentLength).toLowerCase();
}
// example input: getSmallerSegment("Codeup", 3)
// example output: "cod"
</script>
</body>
</html>