3
3
*/
4
4
5
5
// 1. Define three string variables firstName, middleName, and lastName.
6
+ var firstName = "Jeff" ;
7
+ var middleName = "Keegan" ;
8
+ var lastName = "Leary" ;
6
9
7
10
// 2. Declare a function named logFullName that takes no arguments.
8
11
function logFullName ( ) {
9
- // 3. Using template literals, create another variable fullName that combines all three names.
10
- // 4. Print the fullName to the console.
12
+ var fullName = ` ${ firstName } ${ middleName } ${ lastName } ` ;
13
+ console . log ( fullName ) ;
11
14
}
12
15
13
16
/**
14
17
* Task 2: Data Types
15
18
*/
16
19
17
20
// 1. Declare a variable named age and assign it a number.
21
+ var age = 29 ;
18
22
// 2. Declare a variable named isStudent and assign it a boolean value.
23
+ var isStudent = true ;
19
24
// 3. Declare a variable named courses and assign it an array containing three string values representing courses e.g. "Math", "Science", "History".
25
+ var courses = [ "Math" , "Science" , "History" ] ;
20
26
21
27
// 4. Declare a function named logVariableTypes that takes no arguments.
22
28
function logVariableTypes ( ) {
23
- // 5. Print the type of each variable using the typeof operator.
29
+ // 5. Print the type of each variable using the typeof operator.
30
+ console . log ( typeof age ) ;
31
+ console . log ( typeof isStudent ) ;
32
+ console . log ( typeof courses ) ;
24
33
}
25
34
26
35
/**
27
36
* Task 3: Variables Declaration
28
37
*/
29
38
30
39
// 1. Using var, declare a variable named school and assign it a value of "Hogwarts".
40
+ var school = "Hogwarts" ;
31
41
// 2. Using let, declare a variable named subject and assign it a value of "Potions".
42
+ let subject = "Potions" ;
32
43
// 3. Using const, declare a variable named professor and assign it a value of "Snape".
44
+ const professor = "Snape" ;
33
45
34
46
/**
35
47
* Task 4: Basic Operators
36
48
*/
37
49
38
50
// 1. Declare two variables x and y with values 5 and 10 respectively.
51
+ const x = 5 ;
52
+ const y = 10 ;
39
53
40
54
function logAddition ( ) {
41
- // 2. Log the sum of x and y.
55
+ // 2. Log the sum of x and y.
56
+ const sum = x + y ;
57
+ console . log ( sum ) ;
42
58
}
43
59
function logSubtraction ( ) {
44
- // 3. Log the x subtracted from y
60
+ // 3. Log the x subtracted from y
61
+ const subtract = y - x ;
62
+ console . log ( subtract ) ;
45
63
}
46
64
47
65
function logMultiplication ( ) {
48
- // 4. Log the product of x and y.
66
+ // 4. Log the product of x and y.
67
+ const product = x * y ;
68
+ console . log ( product ) ;
49
69
}
50
70
51
71
function logDivision ( ) {
52
- // 5. Log the quotient when x is divided by y.
72
+ // 5. Log the quotient when x is divided by y.
73
+ const quotient = x / y ;
74
+ console . log ( quotient ) ;
53
75
}
54
76
55
77
/**
@@ -63,5 +85,7 @@ let result1 = 3 + 4 * 5;
63
85
let result2 = ( 3 + 4 ) * 5 ;
64
86
65
87
function logResults ( ) {
66
- // 3. Log both result values in your JavaScript environment and check your answers.
88
+ // 3. Log both result values in your JavaScript environment and check your answers.
89
+ console . log ( result1 ) ;
90
+ console . log ( result2 ) ;
67
91
}
0 commit comments