-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle.js
More file actions
116 lines (104 loc) · 2.32 KB
/
style.js
File metadata and controls
116 lines (104 loc) · 2.32 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
/*
1,checck if it is even or odd
num=prompt("enter a number")
if (num%2==0){
console.log("even")}
else{
console.log("odd")}
*/
const prompt = require("prompt-sync")();
let day = prompt("Enter the day of the week in number (1-7):");
// Convert input to number, because prompt returns string
day = Number(day);
switch (day) {
case 1:
console.log("Monday");
break;
case 2:
console.log("Tuesday");
break;
case 3:
console.log("Wednesday");
break;
case 4:
console.log("Thursday");
break;
case 5:
console.log("Friday");
break;
case 6:
console.log("Saturday");
break;
case 7:
console.log("Sunday");
break;
default:
console.log("Invalid day number (must be 1-7).");
}
for(i=0;i<11;i++) {
console.log(i)
}
sum=0
i=0
while(i<6){
sum+=i
i+=1
}
console.log(sum)
var greet=(name="guest")=> console.log(`hello ${name}`);
greet();
var add=(a,b)=> console.log(a+b)
add(5,2);
var square= (x) => x*x
console.log(square(7));
function applyTwice(func, value) {
return func(func(value));
}
const double = x => x * 2;
console.log(applyTwice(double, 5)); // 20
let car={
brand: "utf",
year:2017,
drive: function(){
console.log(`driving ${this.brand}`)
}
}
car.drive();
let arr=[1,3,4,5,6,7]
let my=arr.map(n=>n*2);
console.log(my);
let ka=arr.filter(n=>n%2==0);
console.log(ka);
let ma=arr.reduce((a,b)=>a+b,0);
console.log(ma);
let kaa={ name: "Sara", age: 22 };
let {name,age }=kaa;
console.log(name,age);
let arr1=[1,2] ;
let arr2=[...arr1,3,4];
console.log(arr2);
async function fetchPost() {
try {
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1");
const data = await response.json();
console.log(data); // ✅ Now we can see the post object
} catch (error) {
console.error("Error fetching data:", error); // ⚠️ If something fails
}
}
fetchPost(); // Call the function
/*<form id="myForm">
<input type="text" id="name" placeholder="Enter your name" />
<button type="submit">Submit</button>
</form>
<script>
document.getElementById("myForm").addEventListener("submit", function(event) {
const nameInput = document.getElementById("name").value.trim();
if (nameInput === "") {
event.preventDefault(); // stop form submission
alert("Name cannot be empty!");
}
});
</script>*/
console.log("A"-1
)