-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy path01-0-basics.js
89 lines (73 loc) · 2.38 KB
/
01-0-basics.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
/**
* Task 1: String Manipulation
*/
// 1. Define three string variables firstName, middleName, and lastName.
var firstName = "Sung-Duk";
var middleName = "Duck";
var lastName = "Kang";
// 2. Declare a function named logFullName that takes no arguments.
function logFullName() {
// 3. Using template literals, create another variable fullName that combines all three names.
// 4. Print the fullName to the console.
var fullName = `${firstName} ${middleName} ${lastName}`;
console.log(fullName);
}
/**
* Task 2: Data Types
*/
// 1. Declare a variable named age and assign it a number.
// 2. Declare a variable named isStudent and assign it a boolean value.
// 3. Declare a variable named courses and assign it an array containing three string values representing courses e.g. "Math", "Science", "History".
var age = 29;
var isStudent = true;
var courses = ["Math", "Science", "History"];
// 4. Declare a function named logVariableTypes that takes no arguments.
function logVariableTypes() {
// 5. Print the type of each variable using the typeof operator.
console.log(typeof(age));
console.log(typeof(isStudent));
console.log(typeof(courses));
}
/**
* Task 3: Variables Declaration
*/
// 1. Using var, declare a variable named school and assign it a value of "Hogwarts".
// 2. Using let, declare a variable named subject and assign it a value of "Potions".
// 3. Using const, declare a variable named professor and assign it a value of "Snape".
var school = "Hogwarts";
let subject = "Potions";
const professor = "Snape";
/**
* Task 4: Basic Operators
*/
// 1. Declare two variables x and y with values 5 and 10 respectively.
let x = 5;
let y = 10;
function logAddition() {
// 2. Log the sum of x and y.
console.log(x + y);
}
function logSubtraction() {
// 3. Log the x subtracted from y
console.log(y - x);
}
function logMultiplication() {
// 4. Log the product of x and y.
console.log(x * y);
}
function logDivision() {
// 5. Log the quotient when x is divided by y.
console.log(x / y);
}
/**
* Task 5: Operator Precedence
*/
// 1. Evaluate the following expression without using a calculator or running the code: 3 + 4 * 5.
let result1 = 3 + 4 * 5;
// 2. Now, evaluate this: (3 + 4) * 5.
let result2 = (3 + 4) * 5;
function logResults() {
// 3. Log both result values in your JavaScript environment and check your answers.
console.log(result1);
console.log(result2);
}