-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay02.js
More file actions
160 lines (130 loc) · 4.74 KB
/
Day02.js
File metadata and controls
160 lines (130 loc) · 4.74 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
//Create an array that stores the temperatures recorded over 7 days.
//Use indexing to access the temperature for the 4th day and update it
//to a new value by adding 2 degrees. After that, log the updated temperatures
//for all 7 days to the console.
// let arrTemp = [10, 11, 9, 8, 13, 10, 5];
// arrTemp[3] = arrTemp[3]+2;
// console.log(arrTemp);
//Problem Statement: Write a function called greetUser that prompts the user to enter their name using the prompt() function.
//If the user enters a name, greet them with the message: "Hello, !". If no name is provided (i.e., the user presses "Cancel"
// or enters an empty string), the function should use a default name "Guest" and greet them with: "Hello, Guest!".
//equirements:
//Use a function expression. Ensure the function handles cases where the user cancels or leaves the input empty.
// function userName()
// {
// let name = prompt('PLease, Enter your name : ');
// if(name=='' || name==null){
// return 'Guest';
// }
// else
// {
// return name;
// }
// }
// function greetUser(name)
// {
// console.log(`Hello ${name}`);
// }
// let user = userName();
// greetUser(user);
//You are developing a task management system that tracks pending tasks for the day. Create an array with five tasks.
// Implement the following operations without using specific method references:
// 1- Remove the first task from the list.
// 2- Add two new high-priority tasks to the beginning of the list.
// 3- Replace the last task in the list with a new task.
// 4- Log the updated task list after all operations.
// let arrTask = ['reading', 'writing', 'speaking', 'listening', 'shoping']
// //Removing the first task from the list.
// // let temp = arrTask[0];
// // for(let i=0; i<arrTask.length-1; i++)
// // {
// // arrTask[i]=arrTask[i+1];
// // }
// let arr1 = [];
// for(let i=0; i<arrTask.length-1; i++)
// {
// arr1[i]=arrTask[i+1];
// }
// // console.log(arr1);
// //Add two new high-priority tasks to the beginning of the list.
// let arr2 = [];
// for(let i=0; i<arr1.length+2; i++)
// {
// if(i==0)
// {
// arr2[i]='rivision';
// }
// else if(i==1)
// {
// arr2[i]='breakfast';
// }
// else
// {
// arr2[i]=arr1[i-2];
// }
// }
// console.log(arr2);
// //Replacing the last task in the list with a new task.
// arr2[arr2.length-1]='sleep';
// //Log the updated task list after all operations.
// console.log(arr2);
//Problem Statement: Write a function called generatePassword that takes three parameters: length, includeNumbers, and includeSpecialChars.
// The function should generate a random password of the given length. If the user doesn't specify
// whether to include numbers or special characters, the function should default to including them.
// includeNumbers is a boolean that indicates whether to include numbers in the password.
// Default to true. includeSpecialChars is a boolean that indicates whether to include special characters.
// Default to false. The function should ensure that the generated password meets the following conditions:
// Contains at least one uppercase letter. If includeNumbers is true, includes at least one number.
// If includeSpecialChars is true, includes at least one special character (like @, #, !). Example:
// If generatePassword(10, true, true) is called, it might return a password like "Ab1@deF2Gh".
// function generatePassword(len, includeNumbers, includeSpecialChars) {
// let password = "";
// let i = 0;
// while (i < len) {
// console.log(i);
// if (i < len) {
// password = password + "O";
// i = password.length;
// }
// if (includeNumbers && i < len) {
// password = password + 9;
// i = password.length;
// }
// if (i < len) {
// password = password + "k";
// i = password.length;
// }
// if (i < len) {
// password = password + "W";
// i = password.length;
// }
// if (includeSpecialChars && i < len) {
// password = password + "&";
// i = password.length;
// }
// if (i < len) {
// password = password + "m";
// i = password.length;
// }
// if (i < len) {
// password = password + "s";
// i = password.length;
// }
// if (i < len) {
// password = password + "z";
// i = password.length;
// }
// }
// return password;
// }
// let iN = true;
// let iSC = false;
// let l = +prompt(
// "Enter the length of the password : [length should be greater than 7] "
// );
// iN = prompt("Do you want numbers in your password? enter True or False : ");
// iSC = prompt(
// "Do you want special characters in your password? enter True or False : "
// );
// let pass = generatePassword(l, iN, iSC);
// console.log(pass);