-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini-function-exercises.html
78 lines (53 loc) · 2.56 KB
/
mini-function-exercises.html
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
<!DOCTYPE html>
<html>
<head>
<title>Inline JS</title>
</head>
<body>
<script>
// JavaScript code goes here
// 1. create a 'functions-exercise' branch
// 2. create a HTML file with inline JS to solve the below problems called mini-function-exercises.html
// ===== MINI PROBLEMS
// Write a function, returnFive, that returns the number five. No inputs should be defined.
// You have to write a function that returns the number five
// pieces of data
// name of function is "returnFive"
// no inputs
// output is returns the value of five
function returnFive() {
return 5;
}
console.log(returnFive());
// 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(pValue) {
return (pValue == 5);
}
console.log("return 5 is 5 : " + isFive(5));
console.log("return '5' is 5 : " + isFive('5'));
console.log("return 4 is 5 : " + isFive(4));
// 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(pValue) {
return (pValue.length < 5);
}
console.log("Parangaritimiricuaro is a short word : " + isShortWord('Parangaritimiricuaro'));
console.log("Home is a short word : " + isShortWord('Home'));
// 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(pValue1, pValue2) {
return (pValue1.length == pValue2.length);
}
console.log("Home and Casa are the same length : " + isSameLength('Home', 'Casa'));
console.log("Home and Hogar are the same length : " + isSameLength('Home', 'Hogar'));
// 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(pLine, pTotalChars) {
return pLine.substring(0, pTotalChars).toLowerCase();
}
console.log("The fox is on the run 7 : ", getSmallerSegment("The fox is on the run", 7));
console.log("The fox is on the run 0 : ", getSmallerSegment("The fox is on the run", 0));
console.log("The fox is on the run 50 : ", getSmallerSegment("The fox is on the run", 50));
</script>
</body>