//1. За допомогою циклу знайдіть суму чисел від 1 до 100.
let sum = 0;
for (let i = 1; i <= 100; i++) {
sum += i;
}
console.log(sum);
//2. Зробити конвектор валют за допомогою switch.
let currency = prompt("Enter currency: USD, EUR, UAH");
let amount = +prompt("Enter amount:");
switch (currency) {
case "USD": console.log(amount * 40); break; //40 - current rate of USD to UAH
case "EUR": console.log(amount * 45); break; //45 - current rate of EUR to UAH
case "UAH": console.log(amount); break; //1 - current rate of UAH to UAH
default: console.log("Unknown currency"); break; //if entered wrong currency name
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
//1. За допомогою циклу знайдіть суму чисел від 1 до 100.
let sum = 0;
for (let i = 1; i <= 100; i++) {
sum += i;
}
console.log(sum);
//2. Зробити конвектор валют за допомогою switch.
let currency = prompt("Enter currency: USD, EUR, UAH");
let amount = +prompt("Enter amount:");
switch (currency) {
case "USD": console.log(amount * 40); break; //40 - current rate of USD to UAH
case "EUR": console.log(amount * 45); break; //45 - current rate of EUR to UAH
case "UAH": console.log(amount); break; //1 - current rate of UAH to UAH
default: console.log("Unknown currency"); break; //if entered wrong currency name
}