Holaa ;) vuelvo a dejar mi codigo como referencias!
// 1. Show a welcome message
console.log(`Welcome user! :)`);
// 2. Log a message with a name variable
const userName = `Kevin`;
console.log(`Hi, ${userName}!`);
// 3. Alert the same message
alert(`Hi, ${userName}!`);
// 4. Ask a question and logs
const userAnswer = prompt(`What's your favorite programming language?`);
console.log(userAnswer);
// 5. Add two values
let value1 = 15;
let value2 = 25;
let result = value1 + value2; // 15 + 25 = 40
console.log(`The sum of ${value1} plus ${value2} is equals to ${result}`);
// 6. Subtract two values
value1 = 10;
value2 = 2;
result = value1 - value2; // 10 - 2 = 8
console.log(
`The subtraction of ${value1} minus ${value2} is equals to ${result}`
);
// 7. Check 18 years old
const userAge = +prompt(`Type your age: `);
if (userAge >= 18) {
console.log(`You are an adult!`);
} else {
console.log(`You are still young!`);
}
// 8. Check if it's positive o negative number
const num = +prompt(`Type a number: `);
if (num === 0) {
console.log(`It's zero! (0)`);
} else {
if (num > 0) {
console.log(`It's a positive number! (${num})`);
} else {
console.log(`It's a negative number! (${num})`);
}
}
// 9. Show 1 - 10 using while loop
let count = 1;
// * One way
while (true) {
console.log(count++);
if (count > 10) {
break;
}
}
// * Other way
count = 1;
while (count <= 10) {
console.log(count++);
}
// 10. Grades check
const grade = 9;
if (grade >= 7) {
console.log(`Passed!`);
} else {
console.log(`Failed!`);
}
// 11, 12 & 13 - Math.random
// 11
console.log(Math.random());
// 12
console.log(Math.floor(Math.random() * 10) + 1);
// 13
console.log(Math.floor(Math.random() * 1000) + 1);