-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjs-basics.html
More file actions
102 lines (77 loc) · 2.12 KB
/
js-basics.html
File metadata and controls
102 lines (77 loc) · 2.12 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript Basics</title>
</head>
<body>
<button id="countButton">Click Me</button>
<p>Click Count: <span id="clickCount">0</span></p>
<script>
console.log("hello world")
//🟨Variables
var name = "deep"
var age = "20"
var isStudent = true
//Printing Variables
console.log("Name : " + name)
console.log("Age : " + age)
console.log("Is student : " + isStudent)
//🟨Arithmatic operations
var num1 = 10
var num2 = 5
var sum = num1 + num2
var difference = num1 - num2
var product = num1 / num2
var quotient = num1 / num2
console.log("Sum : " + sum)
console.log("difference : " + difference)
console.log("product : " + product)
console.log("quotient : " + quotient)
//🟨Condional if statemnets
var age = 18
if (age >= 18) {
console.log("you r n adult")
} else {
console.log("you r a minor.")
}
//🟨For Loop
for (i = 0; i <= 5; i++) {
console.log("for loop " + i)
}
//🟨Arrays
var fruits = ["apple", "banana", "orange"]
console.log("First fruit " + fruits[0])
console.log("Number of fruits : " + fruits.length)
for (var i = 0; i < fruits.length; i++) {
console.log("Fruit " + (i + 1) + ": " + fruits[i])
}
//🟨Functions and Call
function greet(name) {
console.log("Hello, " + name + "!")
}
greet("deep")
//🟨User Input
var userInput = prompt("Enter your name:")
console.log("Hello, " + userInput + "!")
//🟨Object
var person = {
firstName: "deep",
lastName: "kothari",
age: 21,
}
console.log("First Name: " + person.firstName)
console.log("Last Name: " + person.lastName)
console.log("Age: " + person.age)
//🟨Event Handling
var count = 0
var clickButton = document.getElementById("countButton")
var clickCount = document.getElementById("clickCount")
clickButton.addEventListener("click", function () {
count++
clickCount.textContent = count
})
</script>
</body>
</html>