-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaScript.js
More file actions
84 lines (76 loc) · 4.24 KB
/
javaScript.js
File metadata and controls
84 lines (76 loc) · 4.24 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
// 1: suaasha kowaad
// Do the following:
// 1. Declare a string variable with the value "1999".
// 2. Convert the string value of "1999" into a number.
// 3. Display the number to the console to "fix" the time machine.
let yearString = "1999"; // Step 1: Declare a string variable with the value "1999".
let yearNumber = Number(yearString); // Step 2: Convert the string value of "1999" into a number.
console.log(yearNumber); // Step 3: Display the number to the console to "fix" the time machine.
// 2: suaasha labaad
// 1. Declare a variable with the number 27 (or another number of your choice).
// 2. Write an if/else statement to check if the number is odd or even.
// 3. If it’s odd, console.log("This number is odd. The thief is tricky!").
// 4. If it’s even, console.log("This number is even. The thief is neat!").
let number = 27; // Step 1: Declare a variable with the number 27.
if (number % 2 === 0) { // Step 2: Check if the number is even.
console.log("This number is even. The thief is neat!"); // Step 4: If it’s even, log this message.
}
else { // Step 3: If it’s odd, log this message.
console.log("This number is odd. The thief is tricky!");
}
// 3: suaasha sadexaad
// 1. Prompts the user to share how they feel today (e.g., happy, sad, tired).
// 2. If the user enters "happy", console.log("I'm glad to hear that!").
// 3. If the user enters "sad", console.log("I'm sorry, hope you feel better soon.").
// 4. If the user enters "tired", console.log("Make sure to get some rest.").
// 5. For any other input, console.log("Thank you for sharing how you feel.").
let userFeeling = prompt("How do you feel today? (happy, sad, tired)"); // Step 1: Prompt the user for their feelings.
if (userFeeling === "happy") { // Step 2: Check if the user is happy.
console.log("I'm glad to hear that!"); // Step 3: Log this message if happy.
}
else if (userFeeling === "sad") { // Step 4: Check if the user is sad.
console.log("I'm sorry, hope you feel better soon."); // Step 5: Log this message if sad.
}
else if (userFeeling === "tired") { // Step 6: Check if the user is tired.
console.log("Make sure to get some rest."); // Step 7: Log this message if tired.
}
else { // Step 8: For any other input, log this message.
console.log("Thank you for sharing how you feel.");
}
// 4: suaasha afaraad
// 1. Prompt the user to enter a temperature in Celsius.
// 2. Convert the temperature to Fahrenheit using the formula F = (C × 9/5) + 32.
// 3. If the temperature is below 0°C, console.log("Ice Alert! It's freezing!").
// 4. If it’s above 30°C, console.log("Fire Alert! It's boiling!").
// 5. Otherwise, console.log("The temperature is normal.").
let celsius = parseFloat(prompt("Enter the temperature in Celsius:")); // Step 1: Prompt the user for temperature in Celsius.
let fahrenheit = (celsius * 9/5) + 32; // Step 2: Convert Celsius to Fahrenheit.
console.log("Temperature in Fahrenheit: " + fahrenheit); // Log the converted temperature.
if (celsius < 0) { // Step 3: Check if the temperature is below 0°C.
console.log("Ice Alert! It's freezing!"); // Log this message if freezing.
}
else if (celsius > 30) { // Step 4: Check if the temperature is above 30°C.
console.log("Fire Alert! It's boiling!"); // Log this message if boiling.
}
else { // Step 5: For normal temperature, log this message.
console.log("The temperature is normal.");
}
// 5: suaasha shanaad
// 1. Print numbers from 1 to 50.
// 2. For multiples of 3, the aliens say "Fizz" instead of the number.
// 3. For multiples of 5, they say "Buzz".
// 4. For numbers divisible by both 3 and 5, they say "FizzBuzz".
for (let i = 1; i <= 50; i++) { // Step 1: Loop through numbers from 1 to 50.
if (i % 3 === 0 && i % 5 === 0) { // Step 4: Check if divisible by both 3 and 5.
console.log("FizzBuzz"); // Log "FizzBuzz" for multiples of both.
}
else if (i % 3 === 0) { // Step 2: Check if divisible by 3.
console.log("Fizz"); // Log "Fizz" for multiples of 3.
}
else if (i % 5 === 0) { // Step 3: Check if divisible by 5.
console.log("Buzz"); // Log "Buzz" for multiples of 5.
}
else {
console.log(i); // Log the number itself if not a multiple of 3 or 5.
}
}