-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
202 lines (126 loc) · 4.66 KB
/
Copy pathscript.js
File metadata and controls
202 lines (126 loc) · 4.66 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
console.log("JavaScript Loaded!");
document.getElementById("btn").addEventListener("click", function () {
alert("Welcome to the website.");
});
document.getElementById("byebtn").addEventListener("click", function () {
alert("Goodbye! See you tomorrow.");
});
// ---------Variables ----------//
//Creating Recipe Variables
const recipeTitle = "Fudgy Double Chocolate Brownies";
const time = 35;
const difficultyLevel = "Easy";
const rating = 5;
const calories = 280;
const authorName = "Satnam Singh";
const dishImageUrl = "recipe-image.jpg";
//Select HTML element by ID
const imgElement = document.getElementById("dish-img");
const titleElement = document.getElementById("title");
const authorNameElement = document.getElementById("author-name");
const timeElement = document.getElementById("time");
const ratingElement = document.getElementById("rating");
const difficultyElement = document.getElementById("difficulty");
const caloriesElement = document.getElementById("calories");
//Display Values on HTML Side
imgElement.src= dishImageUrl;
titleElement.textContent = recipeTitle;
authorNameElement.textContent = authorName;
timeElement.textContent = time + " mins"; // Added text units for clarity
ratingElement.textContent = "⭐ ".repeat(rating); // Converts the number 5 into 5 stars!
difficultyElement.textContent = difficultyLevel;
caloriesElement.textContent = calories + " kcal";
//----------Data Types-----------//
const developerName = "Satnam";
const age = 25;
const isLearningJavaScript = true;
let futureSkill;
let currentJob = null;
document.getElementById("string-output").textContent =
`String: ${developerName}`;
document.getElementById("number-output").textContent =
`Number: ${age}`;
document.getElementById("boolean-output").textContent =
`Boolean: ${isLearningJavaScript}`;
document.getElementById("undefined-output").textContent =
`Undefined: ${futureSkill}`;
document.getElementById("null-output").textContent =
`Null: ${currentJob}`;
//--------Operators---------//
const productName = "Laptop";
const price = 999;
let quantity = 2;
const discount = 100;
const subtotal = price * quantity;
const finalPrice = subtotal - discount;
document.getElementById("product-name").textContent =
`Product: ${productName}`;
document.getElementById("product-price").textContent =
`Price: $${price}`;
document.getElementById("quantity").textContent =
`Quantity: ${quantity}`;
document.getElementById("subtotal").textContent =
`Subtotal: $${subtotal}`;
document.getElementById("discount").textContent =
`Discount: $${discount}`;
document.getElementById("final-price").textContent =
`Final Price: $${finalPrice}`;
//------------Conditions----------//
// Even or Odd Checker
document.getElementById("check-number")
.addEventListener("click", function(){
// Get value from input box
const number = document.getElementById("number-input").value;
// Convert string into number
const enteredNumber = Number(number);
// Check if number is even or odd
if(enteredNumber % 2 === 0){
document.getElementById("result").textContent =
`${enteredNumber} is an Even Number`;
}
else{
document.getElementById("result").textContent =
`${enteredNumber} is an Odd Number`;
}
});
//------------Loops--------//
document.getElementById("print-loop")
.addEventListener("click", function () {
const loopNumber = document.getElementById("loop-number").value;
const enteredLoopNumber = Number(loopNumber);
let output = "";
for (let i = 1; i <= enteredLoopNumber; i++) {
output += `${i} `;
}
document.getElementById("result-loop").textContent = output;
});
//-------------Functions with PERAMETERS-----------//
// Function with a parameter
function showMessage(name) {
alert(`Welcome to the website, ${name}!`);
}
// Button click
document.getElementById("show-message-btn")
.addEventListener("click", function () {
// Get the name from the input
const userName = document.getElementById("user-name").value;
// Call the function and pass the name
showMessage(userName);
});
//-------------DOM (Document Object Model)-----------//
//--------Change Text
document.getElementById("change-title-btn")
.addEventListener("click", function () {
document.getElementById("dom-title").textContent = "Welcome to the DOM Section!";
});
//---------Change Color
document.getElementById("change-color-btn")
.addEventListener("click", function () {
document.getElementById("dom-color").style.color = "blue";;
});
//-------------Change Image
document.getElementById("image-btn")
.addEventListener("click", function () {
document.getElementById("profile-image").src =
"./bulbon.jpeg";
});