Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (101 loc) · 3.92 KB
/
Copy pathscript.js
File metadata and controls
121 lines (101 loc) · 3.92 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
1. Create a function named `sayHello` that alerts a message `Hello World!`.
*/
function sayHello () {
alert(`Hello World!`);
}
/*
2. Create a function named `fullName` with the following steps:
- Prompts a message saying`Enter your first name` and store the value into variable named`firstName`
- Prompts a message saying`Enter your last name` and store the value into variable named`lastName`
- Concat the value of fistName and lastName and store it in another variable named`fullName`.
- Alert`fullName`
- Prompts a message saying `Enter your first name` and store the value into variable named `firstName`
- Prompts a message saying `Enter your last name` and store the value into variable named `lastName`
- Concat the value of fistName and lastName and store it in another variable named `fullName`.
- Alert `fullName`
*/
function fullName () {
let firstName = prompt(`Enter your first name`);
let lastName = prompt(`Enter your last name`);
let fullName = (firstName + " " + lastName);
alert(fullName);
}
fullName ();
fullName ();
/*
3. Create a function named `addTwoNumbers` with the following steps:
- Prompts a message saying`Enter the first number` and store the value into variable named`firstNum`
- Prompts a message saying`Enter the second number` and store the value into variable named`secondNum`
- Concat the value of fistNum and lastNum and store it in another variable named`sum`.
- Alert`sum`
- Prompts a message saying `Enter the first number` and store the value into variable named `firstNum`
- Prompts a message saying `Enter the second number` and store the value into variable named `secondNum`
- Add the value of firstNum and secondNum and store it in another variable named `sum`.
- Alert `sum`
*/
function addTwoNumbers () {
let firstNum = +prompt(`Enter your first number`);
let lastNum = +prompt(`Enter your last number`);
let sum = (firstNum + lastNum);
alert(sum);
}
addTwoNumbers ();
addTwoNumbers ();
/*
4. Create a function named `getTable` with the following steps:
- Prompts a message saying`Enter a number` and store the value into variable named`num`
- Using`console.log` logs the Multiplication Table of the number entered by the user.
- Prompts a message saying `Enter a number` and store the value into variable named `num`
- Using `console.log` logs the Multiplication Table of the number entered by the user.
- Example: Number is 9
9 * 1 = 9
@@ -39,19 +39,17 @@
9 * 10 = 90
*/
function getTable () {
let num = +prompt(`Enter a number`);
for(let i = 1; i <= 10; i++) {
console.log(`${num} * ${i} = ${num * i}`);
}
}
getTable ();
getTable ();
/*
5. Create a function named `isLeapYear` with the following steps:
- Prompts a message saying`Enter a year` and store the value into variable named`year`
- Alert`[year] is a leap year` otherwise`[year] is not a leap year`
- Prompts a message saying `Enter a year` and store the value into variable named`year`
- Alert `[year] is a leap year` otherwise `[year] is not a leap year`
*/
function isLeapYear (){
let year = +prompt(`Enter a year`);
if (year % 400 === 0){
alert(`${year} is a leap year`)
} else if(year % 100 === 0){
alert(`${year} is not a leap year`)
} else if (year % 4 === 0){
alert(`${year} is a leap year`)
} else {
alert(`${year} is not a leap year`)
}
}
isLeapYear ();
isLeapYear ();
/*
6. Create a function named `getFactorial` with the following steps:
- Prompts a message saying`Enter a number` and store the value into variable named`number`
- Alert`The factorial of [number] is [factorial]`
- Prompts a message saying `Enter a number` and store the value into variable named`number`
- Alert `The factorial of [number] is [factorial]`
*/
function getFactorial () {
let num = +prompt(`Enter a number`);
factorial = 1;
for(let i = 1; i <= num; i++){
factorial *= i;
}
alert(`The factorial of ${num} is ${factorial}`);
}
getFactorial ();
getFactorial ();