forked from RachelKoldenhoven/fundamentals-day-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
30_basic_functions.js
87 lines (58 loc) · 1.85 KB
/
30_basic_functions.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
// Remember to look at documentation and ask your partners when you get stuck
// Simple math functions
const add = (a, b) => {
return a + b;
};
const result = add(3, 4);
console.log('The result of add is: ', result);
// Use the example above to write your own functions to solve common math problems
// subtract
// multiply
// divide
// area of rectangle
// your turn! Think of more functions on your own.
// console.log vs return
const addReturn = (a, b) => {
return a + b;
};
const addLog = (a, b) => {
console.log(a + b);
};
const result = addReturn(3, 4);
console.log(result);
addLog(5, 6);
const result2 = addLog(1, 7);
console.log(result2);
// Functions with strings
// Write a function that accepts a name and prints "Hello, name!"
// Write a function that accepts two strings and prints them together in a sentence.
/*
Functions that return a boolean
Write a function that:
1. accepts a number as a parameter
2. evaluates an expression with that number
3. returns true or false based on the expression
*/
let counter = 0;
// 1. Write a function that will add 5 to the counter value each time you invoke it.
// 2. Write a function that will divide the counter value by 3 and return the remainder.
// 3. Write a function that will print the counter value in a sentence.
// 1. Write 2 functions. Both should accept a string as a parameter. In the first, return the string.
// In the second, console.log the string. What do you see in the console when you invoke each one?
// Can you use a variable to catch the return value from the first function?
// Functions calling Functions
const function1 = () => {
console.log("I");
};
const function2 = () => {
console.log("like");
};
const function3 = () => {
console.log("JavaScript!");
};
const allTogether = () => {
function1();
function2();
function3();
};
allTogether();