-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExercise.html
More file actions
84 lines (63 loc) · 1.75 KB
/
Exercise.html
File metadata and controls
84 lines (63 loc) · 1.75 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
<!--
Lesson 7 : Exercises - Functions
!!! NOTE : Do these Exercises, create a HTML file (like Exercise.html)
🟨 visit this link for QuestionBank :-
🟩 https://github.com/deepk2891/Javascript/blob/main/lesson-07/README.md
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Exercises-Functions</title>
</head>
<body>
<script>
//🟨7a.
function greet ()
{
console.log('Good Day!');
}
greet();
//🟨7b.
function greet (name)
{
// console.log(`hello ${ name } !`);
//🟨7c.
if (!name) {
console.log('Hi there !');
}
else {
console.log(`Hello ${ name }`);
}
}
greet();
//🟨7d.
function convertToFahrenheit (celsius)
{
return (celsius * 9 / 5) + 32;
}
console.log(convertToFahrenheit(5));
//🟨7e.
function convertToCelsius (fahrenheit)
{
return (fahrenheit - 32) * 5 / 9;
}
console.log(convertToCelsius(5));
//🟨7f.
function convertToTemperature (degrees,unit)
{
if (unit == 'C') {
const result = convertToFahrenheit(degrees);
return `${ result }F`;
}
else if (unit === 'F') {
const result = convertToCelsius(degrees);
return `${ result }C`;
}
}
console.log(convertToTemperature(25,'C'));
console.log(convertToTemperature(86,'F'));
</script>
</body>
</html>