├── Conditional Statements - Lab ├── Area of Figures.js ├── Even or Odd.js ├── Excellent Result.js ├── Greater Number.js ├── Number 100 - to - 200.js ├── Password Guess.js └── Speed Info.js ├── Conditional Statements Advanced - Exercise ├── Cinema.js ├── Fishing Boat.js ├── Hotel Room.js ├── Journey.js ├── New House.js ├── On Time for the Exam.js ├── Operations Between Numbers.js ├── Ski Trip.js └── Summer Outfit.js ├── Conditional Statements Advanced - Lab ├── Animal Type.js ├── Cinema Ticket.js ├── Day of Week.js ├── Exam │ ├── Bracelet Stand.js │ ├── Computer Firm.js │ ├── Everest.js │ ├── PC Store.js │ ├── Santa1.js │ ├── Santas Holiday.js │ └── Substitute.js ├── Fruit Shop.js ├── Fruit or Vegetable.js ├── Invalid Number.js ├── Number in Range.js ├── Personal Titles.js ├── Small Shop.js ├── Trade Commissions.js ├── Weekend or Working Day.js └── Working Hours.js ├── Conditional Statements Exercise ├── Bonus Score.js ├── Godzilla Vs Kong.js ├── Lunch Break.js ├── Shopping.js ├── Sum Seconds.js ├── Time 15 Minutes.js ├── Toy Shop.js └── World Swimming Record.js ├── First steps in coding - Exercise ├── Basketball Equipment.js ├── Deposit Calculator.js ├── Fish Tank.js ├── Food Delivery.js ├── Radians to Degrees.js ├── Repainting.js ├── Supplies for School.js ├── USD to BGN.js └── Vacation Books List.js ├── First steps in coding -Lab ├── Concatenate Data.js ├── Greeting by Name.js ├── Hello SoftUni.js ├── Inches to Centimeters.js ├── Nums 1 to 10.js ├── Pet Shop.js ├── Square Area.js └── Yard Greening.js ├── For Loop - Exercise ├── Clever Lily.js ├── Histogram.js ├── Multiplication Table.js ├── Numbers 1000, ending in 7.js ├── Oscars.js ├── Salary.js ├── Tennis Ranklist.js └── Trekking Mania.js ├── For Loop - Lab ├── Character Sequence.js ├── Even Powers of 2.js ├── Numbers Divisible by 9.js ├── Numbers 1 N with Step 3.js ├── Numbers N to 1.js ├── Numbers from 1 to 100.js ├── Sum of Numbers.js └── Vowels Sum.js ├── For-Loop - More Exercises ├── Back To The Past.js ├── Bills.js ├── Equal Pairs.js ├── Football Legue.js ├── Game Of Intervals.js ├── Grades.js ├── Hospital.js ├── Logistics.js ├── clock.js ├── clockPart 2.js └── footballLegue2.js ├── Nested Loops - Exercise ├── Cinema Tickets.js ├── Equal Sums Even Odd Position.js ├── Number Pyramid.js ├── Special Numbers.js ├── Sum Prime Non Prime.js └── Train The Trainers.js ├── README.md ├── While Loop - Exercise ├── Cake.js ├── Coins.js ├── Exam Preparation.js ├── Moving.js ├── Old Books.js ├── Vacation.js └── Walking.js ├── While Loop - Lab ├── Account Balance.js ├── Graduation.js ├── Max Number.js ├── Min Number.js ├── Password.js ├── Read Text.js ├── Sequence 2k+1.js └── Sum Numbers.js └── While-Loop - More Exercises ├── Average Number.js ├── Dishwasher.js └── Numbers Divided by 3 Without Reminder.js /Conditional Statements - Lab/Area of Figures.js: -------------------------------------------------------------------------------- 1 | function areaOfFigure(input) { 2 | let typeFigure = input[0]; 3 | // let area = 0; 4 | 5 | if (typeFigure === "square") { 6 | let side = Number(input[1]); 7 | 8 | console.log((side * side).toFixed(3)); 9 | 10 | 11 | } else if (typeFigure === "rectangle") { 12 | let side = Number(input[1]); 13 | let sideA = Number(input[2]); 14 | 15 | console.log((side * sideA).toFixed(3)); 16 | 17 | } else if (typeFigure === "circle") { 18 | let radius = Number(input[1]); 19 | // console.log((Math.PI * radius * radius).toFixed(3)); 20 | console.log((Math.PI * (radius ** 2)).toFixed(3)) 21 | 22 | 23 | 24 | } else if (typeFigure === "triangle") { 25 | let side = Number(input[1]); 26 | let high = Number(input[2]); 27 | 28 | console.log((side * high / 2).toFixed(3)); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Conditional Statements - Lab/Even or Odd.js: -------------------------------------------------------------------------------- 1 | function evenOrOdd(input) { 2 | number = Number(input[0]); 3 | 4 | if (number % 2 === 0) { 5 | console.log("even"); 6 | } 7 | else { 8 | console.log("odd"); 9 | } 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /Conditional Statements - Lab/Excellent Result.js: -------------------------------------------------------------------------------- 1 | function excellentResult(input) { 2 | grade = Number(input[0]); 3 | 4 | if (grade >= 5.50) { 5 | console.log("Excellent!"); 6 | } 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /Conditional Statements - Lab/Greater Number.js: -------------------------------------------------------------------------------- 1 | function solve(input) { 2 | number = Number(input[0]); 3 | 4 | if (number < 100) { 5 | console.log("Less than 100"); 6 | } 7 | if (number >= 100 && number <= 200) { 8 | console.log("Between 100 and 200"); 9 | } 10 | if (number > 200) { 11 | console.log("Greater than 200"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Conditional Statements - Lab/Number 100 - to - 200.js: -------------------------------------------------------------------------------- 1 | function solve(input) { 2 | number = Number(input[0]); 3 | 4 | if (number < 100) { 5 | console.log("Less than 100") 6 | } else if (number >= 100) { 7 | console.log("Between 100 and 200"); 8 | } else if (number >= 200) { 9 | console.log("Greater than 200"); 10 | } 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Conditional Statements - Lab/Password Guess.js: -------------------------------------------------------------------------------- 1 | function passwordGuess(input) { 2 | password = String(input[0]); 3 | 4 | if (password === "s3cr3t!P@ssw0rd") { 5 | console.log("Welcome"); 6 | } 7 | else { 8 | console.log("Wrong password!"); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Conditional Statements - Lab/Speed Info.js: -------------------------------------------------------------------------------- 1 | function speedInfo(input) { 2 | speed = Number(input[0]); 3 | 4 | if (speed <= 10) { 5 | console.log("slow"); 6 | } else if (speed <= 50) { 7 | console.log("average"); 8 | } else if (speed <= 150) { 9 | console.log("fast"); 10 | } else if (speed <= 1000) { 11 | console.log("ultra fast"); 12 | } else { 13 | console.log("extremely fast"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/Cinema.js: -------------------------------------------------------------------------------- 1 | function cinema(input) { 2 | let typeProject = String(input[0]); 3 | let countRows = Number(input[1]); 4 | let countColumns = Number(input[2]); 5 | 6 | let totalIncomes = 0; 7 | 8 | if (typeProject === "Premiere") { 9 | totalIncomes = countRows * countColumns * 12.00; 10 | } else if (typeProject === "Normal") { 11 | totalIncomes = countRows * countColumns * 7.50; 12 | } else if (typeProject === "Discount") { 13 | totalIncomes = countRows * countColumns * 5.00; 14 | } 15 | console.log(`${totalIncomes.toFixed(2)}`); 16 | } -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/Fishing Boat.js: -------------------------------------------------------------------------------- 1 | function fishingBoat(input) { 2 | let budget = Number(input[0]); 3 | let season = String(input[1]); 4 | let countFishermen = Number(input[2]); 5 | 6 | let boatRent = 0; 7 | 8 | if (season === "Spring") { 9 | boatRent = 3000; 10 | } else if (season === "Summer" || season === "Autumn") { 11 | boatRent = 4200; 12 | } else if (season === "Winter") { 13 | boatRent = 2600; 14 | } 15 | 16 | if (countFishermen <= 6) { 17 | boatRent *= 0.9; 18 | } else if (countFishermen > 7 && countFishermen <= 11) { 19 | boatRent *= 0.85; 20 | } else if (countFishermen > 12) { 21 | boatRent *= 0.75; 22 | } 23 | if ((countFishermen % 2 === 0) & (season !== "Autumn")) { 24 | boatRent *= 0.95; 25 | } 26 | 27 | let diff = Math.abs(budget - boatRent); 28 | if (budget >= boatRent) { 29 | console.log(`Yes! You have ${diff.toFixed(2)} leva left.`); 30 | } else { 31 | console.log(`Not enough money! You need ${diff.toFixed(2)} leva.`); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/Hotel Room.js: -------------------------------------------------------------------------------- 1 | function hotelRoom(input) { 2 | let month = String(input[0]); 3 | let countOvernightStays = Number(input[1]); 4 | 5 | let studioPrice = 0; 6 | let apartmentPrice = 0; 7 | 8 | let discountStudio = 1; 9 | let discountApartment = 1; 10 | 11 | let studio; 12 | let apartment; 13 | 14 | switch (month) { 15 | case "May": 16 | case "October": 17 | studio = 50; 18 | apartment = 65; 19 | break; 20 | 21 | case "June": 22 | case "September": 23 | studio = 75.2; 24 | apartment = 68.7; 25 | break; 26 | 27 | case "July": 28 | case "August": 29 | studio = 76; 30 | apartment = 77; 31 | break; 32 | } 33 | 34 | if (countOvernightStays > 7 && countOvernightStays <= 14 && 35 | (month === "May" || month === "October")) { 36 | discountStudio = 0.95; 37 | } else if (countOvernightStays > 14 && 38 | (month === "May" || month === "October")) { 39 | discountStudio = 0.7; 40 | } else if (countOvernightStays > 14 && 41 | (month === "June" || month === "September")) { 42 | discountStudio = 0.8; 43 | } 44 | 45 | if (countOvernightStays > 14) { 46 | discountApartment = 0.9; 47 | } 48 | 49 | studioPrice = studio * countOvernightStays * discountStudio; 50 | apartmentPrice = apartment * countOvernightStays * discountApartment; 51 | 52 | console.log(`Apartment: ${apartmentPrice.toFixed(2)} lv.`); 53 | console.log(`Studio: ${studioPrice.toFixed(2)} lv.`); 54 | } 55 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/Journey.js: -------------------------------------------------------------------------------- 1 | function journey(input) { 2 | let budget = Number(input[0]); 3 | let season = String(input[1]); 4 | 5 | let moneySpent = 0; 6 | 7 | if (budget <= 100) { 8 | if (season === "summer") { 9 | moneySpent = 0.30 * budget; 10 | console.log("Somewhere in Bulgaria"); 11 | console.log(`Camp - ${moneySpent.toFixed(2)}`); 12 | } else if (season === "winter") { 13 | moneySpent = 0.70 * budget; 14 | console.log("Somewhere in Bulgaria"); 15 | console.log(`Hotel - ${moneySpent.toFixed(2)}`); 16 | } 17 | } 18 | 19 | if (budget <= 1000 && budget > 100) { 20 | if (season === "summer") { 21 | moneySpent = 0.40 * budget; 22 | console.log("Somewhere in Balkans"); 23 | console.log(`Camp - ${moneySpent.toFixed(2)}`); 24 | } else if (season === "winter") { 25 | moneySpent = 0.80 * budget; 26 | console.log("Somewhere in Balkans"); 27 | console.log(`Hotel - ${moneySpent.toFixed(2)}`); 28 | } 29 | } 30 | 31 | if (budget > 1000) { 32 | moneySpent = 0.90 * budget; 33 | console.log("Somewhere in Europe"); 34 | console.log(`Hotel - ${moneySpent.toFixed(2)}`); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/New House.js: -------------------------------------------------------------------------------- 1 | function newHouse(input) { 2 | let typeOfFlowers = String(input[0]); 3 | let countFlowers = Number(input[1]); 4 | let budget = Number(input[2]); 5 | 6 | let nededMoney = 0; 7 | 8 | if (typeOfFlowers === "Roses") { 9 | nededMoney = countFlowers * 5; 10 | if (countFlowers > 80) { 11 | nededMoney *= 0.9; 12 | } 13 | } else if (typeOfFlowers === "Dahlias") { 14 | nededMoney = countFlowers * 3.80; 15 | if (countFlowers > 90) { 16 | nededMoney *= 0.85; 17 | } 18 | } else if (typeOfFlowers === "Tulips") { 19 | nededMoney = countFlowers * 2.80; 20 | if (countFlowers > 80) { 21 | nededMoney *= 0.85; 22 | } 23 | } else if (typeOfFlowers === "Narcissus") { 24 | nededMoney = countFlowers * 3; 25 | if (countFlowers < 120) { 26 | nededMoney *= 1.15; 27 | } 28 | } else if (typeOfFlowers === "Gladiolus") { 29 | nededMoney = countFlowers * 2.50; 30 | if (countFlowers < 80) { 31 | nededMoney *= 1.20 32 | } 33 | } 34 | 35 | if (budget >= nededMoney) { 36 | console.log(`Hey, you have a great garden with ${countFlowers} ${typeOfFlowers} and ${(budget - nededMoney).toFixed(2)} leva left.`); 37 | } else { 38 | console.log(`Not enough money, you need ${(nededMoney - budget).toFixed(2)} leva more.`); 39 | } 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/On Time for the Exam.js: -------------------------------------------------------------------------------- 1 | function timeForExam(input) { 2 | let hourOnTheExam = Number(input[0]); 3 | let minuteOnTheExam = Number(input[1]); 4 | let hourArrive = Number(input[2]); 5 | let minuteArrive = Number(input[3]); 6 | 7 | let timeExam = hourOnTheExam * 60 + minuteOnTheExam; 8 | let timeArrive = hourArrive * 60 + minuteArrive; 9 | 10 | if (timeExam < timeArrive) { 11 | console.log("Late"); 12 | let diff = Math.abs(timeExam - timeArrive); 13 | let h = Math.floor(diff / 60); 14 | let m = diff % 60; 15 | if (h > 0) { 16 | if (m < 10) { 17 | console.log(`${h}:0${m} hours after the start`) 18 | } else { 19 | console.log(`${h}:${m} hours after the start`) 20 | } 21 | } else { 22 | console.log(` ${m} minutes after the start`); 23 | } 24 | } else if (timeArrive <= timeExam && 25 | Math.abs(timeExam - timeArrive) <= 30) { 26 | console.log("On time"); 27 | let diff = Math.abs(timeArrive - timeExam); 28 | if (diff > 0) { 29 | console.log(`${diff} minutes before the start`); 30 | } 31 | } else { 32 | console.log("Early"); 33 | let diff = Math.abs(timeExam - timeArrive); 34 | let h = Math.floor(diff / 60); 35 | let m = diff % 60; 36 | if (h > 0) { 37 | if (m < 10) { 38 | console.log(`${h}:0${m} hours before the start`) 39 | } else { 40 | console.log(`${h}:${m} hours before the start`) 41 | } 42 | } else { 43 | console.log(` ${m} minutes before the start`); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/Operations Between Numbers.js: -------------------------------------------------------------------------------- 1 | function operationBetweenNumbers(input) { 2 | let n1 = Number(input[0]); 3 | let n2 = Number(input[1]); 4 | let operator = String(input[2]); 5 | 6 | let result = 0; 7 | let oddOrEven = "odd"; 8 | 9 | if (operator === "+" || 10 | operator === "-" || 11 | operator === "*") { 12 | if (operator === "+") { 13 | result = n1 + n2; 14 | } else if (operator === "-") { 15 | result = n1 - n2; 16 | } else if (operator === "*") { 17 | result = n1 * n2; 18 | } 19 | } 20 | 21 | if (operator === "+" || 22 | operator === "-" || 23 | operator === "*") { 24 | if (result % 2 === 0) { 25 | oddOrEven = "even"; 26 | console.log(`${n1} ${operator} ${n2} = ${result} - ${oddOrEven}`); 27 | } else { 28 | oddOrEven = "odd"; 29 | console.log(`${n1} ${operator} ${n2} = ${result} - ${oddOrEven}`); 30 | } 31 | } 32 | 33 | if (operator === "/" || operator === "%") { 34 | if (n2 === 0) { 35 | console.log(`Cannot divide ${n1} by zero`); 36 | } else if (operator === "/") { 37 | result = n1 / n2; 38 | console.log(`${n1} / ${n2} = ${result.toFixed(2)}`); 39 | } else if (operator === "%") { 40 | result = n1 % n2; 41 | console.log(`${n1} % ${n2} = ${result}`); 42 | } 43 | } 44 | 45 | 46 | } -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/Ski Trip.js: -------------------------------------------------------------------------------- 1 | function skiTrip(input) { 2 | let countDays = Number(input[0]); 3 | let typeOfRoom = String(input[1]); 4 | let grade = String(input[2]); 5 | 6 | let nights = countDays - 1; 7 | let result = 0; 8 | 9 | if (typeOfRoom === "room for one person") { 10 | result = nights * 18; 11 | } else if (typeOfRoom === "apartment") { 12 | result = nights * 25; 13 | if (countDays < 10) { 14 | result *= 0.70; 15 | } else if (countDays >= 10 && countDays <= 15) { 16 | result *= 0.65; 17 | } else { 18 | result *= 0.5; 19 | } 20 | } else if (typeOfRoom === "president apartment") { 21 | result = nights * 35; 22 | if (countDays < 10) { 23 | result *= 0.9; 24 | } else if (countDays >= 10 && countDays <= 15) { 25 | result *= 0.85; 26 | } else { 27 | result *= 0.80; 28 | } 29 | } 30 | 31 | if (grade === "positive") { 32 | result *= 1.25; 33 | } else { 34 | result *= 0.90; 35 | } 36 | 37 | console.log(`${result.toFixed(2)}`); 38 | } 39 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Exercise/Summer Outfit.js: -------------------------------------------------------------------------------- 1 | function summerOutfits(input) { 2 | let degreess = Number(input[0]); 3 | let timeOfDay = String(input[1]); 4 | 5 | let outfit; 6 | let shoes; 7 | 8 | if (degreess >= 10 && degreess <= 18) { 9 | if (timeOfDay === "Morning") { 10 | outfit = "Sweatshirt"; 11 | shoes = "Sneakers"; 12 | } else if (timeOfDay === "Afternoon" || timeOfDay === "Evening") { 13 | outfit = "Shirt"; 14 | shoes = "Moccasins"; 15 | } 16 | } else if (degreess > 18 && degreess <= 24) { 17 | if (timeOfDay === "Morning" || timeOfDay === "Evening") { 18 | outfit = "Shirt"; 19 | shoes = "Moccasins;"; 20 | } else if (timeOfDay === "Afternoon") { 21 | outfit = "T-Shirt"; 22 | shoes = "Sandals"; 23 | } 24 | } else if (degreess >= 25) { 25 | if (timeOfDay === "Morning") { 26 | outfit = "T-shirt"; 27 | shoes = "Sandals"; 28 | } else if (timeOfDay === "Afternoon") { 29 | outfit = "Swim Suit"; 30 | shoes = "Barefoot"; 31 | } else if (timeOfDay === "Evening") { 32 | outfit = "Shirt"; 33 | shoes = "Moccasins"; 34 | } 35 | } 36 | console.log(`It's ${degreess} degrees, get your ${outfit} and ${shoes}.`); 37 | } 38 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Animal Type.js: -------------------------------------------------------------------------------- 1 | function animalType(input) { 2 | let typeOfAnimal = String(input[0]); 3 | 4 | switch (typeOfAnimal) { 5 | case "dog": console.log("mammal"); break 6 | case "crocodile": 7 | case "tortoise": 8 | case "snake": 9 | console.log("reptile"); 10 | break 11 | default: console.log("unknown"); break; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Cinema Ticket.js: -------------------------------------------------------------------------------- 1 | function tickets(input) { 2 | day = String(input[0]); 3 | 4 | if (day === "Monday" || day === "Tuesday" || day === "Friday") { 5 | console.log(12) 6 | } else if (day === "Wednesday" || day === "Thursday") { 7 | console.log(14); 8 | } else if (day === "Saturday" || day === "Sunday") { 9 | console.log(16); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Day of Week.js: -------------------------------------------------------------------------------- 1 | function dayOfWeek(input) { 2 | let num = Number(input[0]); 3 | 4 | switch (num) { 5 | case 1: console.log("Monday"); break; 6 | case 2: console.log("Tuesday"); break; 7 | case 3: console.log("Wednesday"); break; 8 | case 4: console.log("Thursday"); break; 9 | case 5: console.log("Friday"); break; 10 | case 6: console.log("Saturday"); break; 11 | case 7: console.log("Sunday"); break; 12 | default: console.log("Error"); break 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Exam/Bracelet Stand.js: -------------------------------------------------------------------------------- 1 | function braceletStand(input) { 2 | let pocketMoney = Number(input[0]); // for day 3 | let moneyEarn = Number(input[1]); // per day of sales 4 | let expense = Number(input[2]); // for the whole period 5 | let priceForGift = Number(input[3]); 6 | 7 | let savedMoney = 5 * pocketMoney; 8 | let winsMoney = 5 * moneyEarn; 9 | let totalWinsMoney = savedMoney + winsMoney; 10 | 11 | let totalExpense = totalWinsMoney - expense; 12 | 13 | if (totalExpense > priceForGift) { 14 | console.log( 15 | `Profit: ${totalExpense.toFixed(2)} BGN, the gift has been purchased.` 16 | ); 17 | } else { 18 | console.log( 19 | `Insufficient money: ${(priceForGift - totalExpense).toFixed(2)} BGN.` 20 | ); 21 | } 22 | } 23 | braceletStand(["5.12", "32.05", "15", "150"]); 24 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Exam/Computer Firm.js: -------------------------------------------------------------------------------- 1 | function pcFirm(input) { 2 | let countOfPC = Number(input[0]); 3 | 4 | let rate = String; 5 | let possibleSold = 0; 6 | let averageRate = 0; 7 | let makedSold = 0; 8 | let totalSold = 0; 9 | 10 | for (i = 1; i <= countOfPC; i += 1) { 11 | rate = String(input[i]); 12 | possibleSold = Number(rate[0] + rate[1]); 13 | rate = rate[2]; 14 | if (rate === "2") { 15 | makedSold = possibleSold * 0; 16 | totalSold += makedSold; 17 | } 18 | if (rate === "3") { 19 | makedSold = possibleSold * 0.5; 20 | totalSold += makedSold; 21 | } 22 | if (rate === "4") { 23 | makedSold = possibleSold * 0.7; 24 | totalSold += makedSold; 25 | } 26 | if (rate === "5") { 27 | makedSold = possibleSold * 0.85; 28 | totalSold += makedSold; 29 | } 30 | if (rate === "6") { 31 | totalSold += possibleSold; 32 | } 33 | averageRate += Number(rate); 34 | } 35 | 36 | console.log(totalSold.toFixed(2)); 37 | console.log((averageRate / countOfPC).toFixed(2)); 38 | } -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Exam/Everest.js: -------------------------------------------------------------------------------- 1 | function everest(input) { 2 | let index = 0; 3 | let command = input[index]; 4 | 5 | let climbedMeters = 5364; 6 | 7 | let daysMetre = Number; 8 | 9 | let countDays = 1; // counter 10 | 11 | while (command !== "END") { 12 | if (command === "Yes") { 13 | countDays += 1; 14 | if (countDays > 5) { 15 | break; 16 | } 17 | } 18 | 19 | index += 1; 20 | daysMetre = Number(input[index]); 21 | climbedMeters += daysMetre; 22 | 23 | if (climbedMeters >= 8848) { 24 | break; 25 | } 26 | index += 1; 27 | command = input[index]; 28 | } 29 | if (climbedMeters >= 8848) { 30 | console.log(`Goal reached for ${countDays} days!`); 31 | } 32 | 33 | if (command === "END" || countDays > 5) { 34 | console.log("Failed!"); 35 | console.log(climbedMeters); 36 | } 37 | } 38 | everest(["Yes", "1254", "Yes", "1402", "No", "250", "Yes", "635"]); 39 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Exam/PC Store.js: -------------------------------------------------------------------------------- 1 | function pcStore(input){ 2 | let priceCPU = Number(input[0]); // CPU - processor in dollars 3 | let priceVGA = Number(input[1]); // VGA - video graphic in dollars 4 | let priceRAM = Number(input[2]); // price in dollars for 1 RAM memory 5 | let countRAM = Number(input[3]); // RAM memory 6 | let percentageDiscout = Number(input[4]); 7 | 8 | let CPU = priceCPU * 1.57; // in lv. 9 | let VGA = priceVGA * 1.57; // in lv. 10 | let RAM = priceRAM * 1.57; // in lv. 11 | let totalRAM = RAM * countRAM; 12 | let priceCUPAfterDiscount = CPU -(CPU * percentageDiscout); 13 | let VGAAfterDisocunt = VGA - (VGA * percentageDiscout); 14 | 15 | let totalPrice = priceCUPAfterDiscount + VGAAfterDisocunt + totalRAM; 16 | 17 | console.log(`Money needed - ${totalPrice.toFixed(2)} leva.`); 18 | 19 | } 20 | pcStore(["200", 21 | "100", 22 | "80", 23 | "1", 24 | "0.01"]) -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Exam/Santa1.js: -------------------------------------------------------------------------------- 1 | function santaHoliday(input) { 2 | let countDays = Number(input[0]); // for stay 3 | let typeOfRoom = String(input[1]); 4 | let grade = String(input[2]); 5 | 6 | let nights = countDays - 1; 7 | let result = 0; 8 | 9 | switch (typeOfRoom) { 10 | case "room for one person": 11 | result = nights * 18; 12 | break; 13 | case "apartment": 14 | result = nights * 25; 15 | if (countDays < 10) { 16 | result *= 0.7; 17 | } else if (countDays >= 10 && countDays <= 15) { 18 | result *= 0.65; 19 | } else { 20 | result *= 0.5; 21 | } 22 | break; 23 | case "president apartment": 24 | result = nights * 35; 25 | if (countDays < 10) { 26 | result *= 0.9; 27 | } else if (countDays >= 10 && countDays <= 15) { 28 | result *= 0.85; 29 | } else { 30 | result *= 0.8; 31 | } 32 | break; 33 | } 34 | if (grade === "positive") { 35 | result *= 1.25; 36 | } else { 37 | result *= 0.9; 38 | } 39 | console.log(`${result.toFixed(2)}`); 40 | } 41 | santaHoliday(["2", "apartment", "positive"]); 42 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Exam/Santas Holiday.js: -------------------------------------------------------------------------------- 1 | function santasHoliday(input) { 2 | let countDays = Number(input[0]); // for stay 3 | let typeOfRoom = String(input[1]); 4 | let grade = String(input[2]); 5 | 6 | let nights = countDays - 1; 7 | let result = 0; 8 | 9 | if(typeOfRoom === "room for one person"){ 10 | result = nights * 18; 11 | }else if(typeOfRoom === "apartment"){ 12 | result = nights * 25; 13 | if(countDays < 10){ 14 | result *= 0.70; 15 | }else if(countDays >= 10 && countDays <= 15){ 16 | result *= 0.65; 17 | }else{ 18 | result *= 0.5; 19 | } 20 | }else if(typeOfRoom === "president apartment"){ 21 | result = nights * 35; 22 | if(countDays < 10){ 23 | result *= 0.9; 24 | }else if(countDays >= 10 && countDays <= 15){ 25 | result *= 0.85; 26 | }else{ 27 | result *= 0.80; 28 | } 29 | } 30 | 31 | if(grade === "positive"){ 32 | result *= 1.25; 33 | }else{ 34 | result *= 0.90; 35 | } 36 | 37 | console.log(`${result.toFixed(2)}`); 38 | } 39 | santasHoliday(["2", 40 | "apartment", 41 | "positive"]) 42 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Exam/Substitute.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyklecharova/SoftUni--JavaScript-Basics/4b2a8395bc37fc5993c12c2def690d10293f3ac1/Conditional Statements Advanced - Lab/Exam/Substitute.js -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Fruit Shop.js: -------------------------------------------------------------------------------- 1 | function fruitShop(input) { 2 | let fruit = String(input[0]); 3 | let dayOfWeek = String(input[1]); 4 | let quantity = Number(input[2]); 5 | let rezult = 0; 6 | 7 | if ( 8 | dayOfWeek === "Monday" || 9 | dayOfWeek === "Tuesday" || 10 | dayOfWeek === "Wednesday" || 11 | dayOfWeek === "Thursday" || 12 | dayOfWeek === "Friday" 13 | ) { 14 | switch (fruit) { 15 | case "banana": 16 | rezult = quantity * 2.5; 17 | break; 18 | case "apple": 19 | rezult = quantity * 1.2; 20 | break; 21 | case "orange": 22 | rezult = quantity * 0.85; 23 | break; 24 | case "grapefruit": 25 | rezult = quantity * 1.45; 26 | break; 27 | case "kiwi": 28 | rezult = quantity * 2.7; 29 | break; 30 | case "pineapple": 31 | rezult = quantity * 5.5; 32 | break; 33 | case "grapes": 34 | rezult = quantity * 3.85; 35 | break; 36 | } 37 | } else if (dayOfWeek === "Sunday" || dayOfWeek === "Saturday") { 38 | switch (fruit) { 39 | case "banana": 40 | rezult = quantity * 2.7; 41 | break; 42 | case "apple": 43 | rezult = quantity * 1.25; 44 | break; 45 | case "orange": 46 | rezult = quantity * 0.9; 47 | break; 48 | case "grapefruit": 49 | rezult = quantity * 1.6; 50 | break; 51 | case "kiwi": 52 | rezult = quantity * 3.0; 53 | break; 54 | case "pineapple": 55 | rezult = quantity * 5.6; 56 | break; 57 | case "grapes": 58 | rezult = quantity * 4.2; 59 | break; 60 | } 61 | } 62 | if (rezult === 0) { 63 | console.log("error"); 64 | } else { 65 | console.log(`${rezult.toFixed(2)}`); 66 | } 67 | } -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Fruit or Vegetable.js: -------------------------------------------------------------------------------- 1 | function FruitOrVegetable(input) { 2 | let nameProduct = String(input[0]); 3 | 4 | switch (nameProduct) { 5 | case "banana": 6 | case "apple": 7 | case "kiwi": 8 | case "cherry": 9 | case "lemon": 10 | case "grapes": 11 | console.log("fruit"); 12 | break; 13 | case "tomato": 14 | case "cucumber": 15 | case "pepper": 16 | case "carrot": 17 | console.log("vegetable"); 18 | break; 19 | default: 20 | console.log("unknown"); 21 | break; 22 | 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Invalid Number.js: -------------------------------------------------------------------------------- 1 | function validNumber(input) { 2 | let number = Number(input[0]); 3 | 4 | if ((number >= 100 && number <= 200) || number === 0) { 5 | 6 | } else { 7 | console.log("invalid"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Number in Range.js: -------------------------------------------------------------------------------- 1 | function numberInRange(input) { 2 | let number = Number(input[0]); 3 | 4 | if (number >= -100 && number <= 100 && number !== 0) { 5 | console.log("Yes"); 6 | } else { 7 | console.log("No") 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Personal Titles.js: -------------------------------------------------------------------------------- 1 | function personal(input) { 2 | let ages = Number(input[0]); 3 | let gender = String(input[1]); 4 | 5 | if (gender === "m") { 6 | if (ages >= 16) { 7 | console.log("Mr."); 8 | } else { 9 | console.log("Master"); 10 | } 11 | } else { 12 | if (gender === "f") { 13 | if (ages >= 16) { 14 | console.log("Ms."); 15 | } else { 16 | console.log("Miss"); 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Small Shop.js: -------------------------------------------------------------------------------- 1 | function smallShop(input) { 2 | let product = String(input[0]); 3 | let town = String(input[1]); 4 | let quantity = Number(input[2]); 5 | 6 | price = 0; 7 | 8 | if (town === "Sofia") { 9 | if (product === "coffee") { 10 | price = quantity * 0.50; 11 | } else if (product === "water") { 12 | price = quantity * 0.80; 13 | } else if (product === "beer") { 14 | price = quantity * 1.20; 15 | } else if (product === "sweets") { 16 | price = quantity * 1.45; 17 | } else if (product === "peanuts") { 18 | price = quantity * 1.60; 19 | } 20 | } 21 | 22 | if (town === "Plovdiv") { 23 | if (product === "coffee") { 24 | price = quantity * 0.40; 25 | } else if (product === "water") { 26 | price = quantity * 0.70; 27 | } else if (product === "beer") { 28 | price = quantity * 1.15; 29 | } else if (product === "sweets") { 30 | price = quantity * 1.30; 31 | } else if (product === "peanuts") { 32 | price = quantity * 1.50; 33 | } 34 | } 35 | 36 | if (town === "Varna") { 37 | if (product === "coffee") { 38 | price = quantity * 0.45; 39 | } else if (product === "water") { 40 | price = quantity * 0.70; 41 | } else if (product === "beer") { 42 | price = quantity * 1.10; 43 | } else if (product === "sweets") { 44 | price = quantity * 1.35; 45 | } else if (product === "peanuts") { 46 | price = quantity * 1.55; 47 | } 48 | } console.log(price); 49 | } 50 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Trade Commissions.js: -------------------------------------------------------------------------------- 1 | function tradeCommission(input) { 2 | let town = String(input[0]); 3 | let volumeSalese = Number(input[1]); 4 | 5 | let result = 0; 6 | 7 | if (town === "Sofia") { 8 | if (volumeSalese >= 0 && volumeSalese <= 500) { 9 | result = volumeSalese * 0.05; 10 | } else if (volumeSalese > 500 && volumeSalese <= 1000) { 11 | result = volumeSalese * 0.07; 12 | } else if (volumeSalese > 1000 && volumeSalese <= 10000) { 13 | result = volumeSalese * 0.08; 14 | } else if (volumeSalese > 10000) { 15 | result = volumeSalese * 0.12; 16 | } 17 | 18 | } 19 | 20 | if (town === "Varna") { 21 | if (volumeSalese >= 0 && volumeSalese <= 500) { 22 | result = volumeSalese * 0.045; 23 | } else if (volumeSalese > 500 && volumeSalese <= 1000) { 24 | result = volumeSalese * 0.075; 25 | } else if (volumeSalese > 1000 && volumeSalese <= 10000) { 26 | result = volumeSalese * 0.1; 27 | } else if (volumeSalese > 10000) { 28 | result = volumeSalese * 0.13; 29 | } 30 | } 31 | 32 | if (town === "Plovdiv") { 33 | if (volumeSalese >= 0 && volumeSalese <= 500) { 34 | result = volumeSalese * 0.055; 35 | } else if (volumeSalese > 500 && volumeSalese <= 1000) { 36 | result = volumeSalese * 0.08; 37 | } else if (volumeSalese > 1000 && volumeSalese <= 10000) { 38 | result = volumeSalese * 0.12; 39 | } else if (volumeSalese > 10000) { 40 | result = volumeSalese * 0.145; 41 | } 42 | } 43 | if (result !== 0) { 44 | console.log(result.toFixed(2)) 45 | } else { 46 | console.log("error") 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Weekend or Working Day.js: -------------------------------------------------------------------------------- 1 | function weekendOrWorkingDay(input) { 2 | let day = String(input[0]); 3 | 4 | switch (day) { 5 | case "Monday": 6 | case "Tuesday": 7 | case "Wednesday": 8 | case "Thursday": 9 | case "Friday": 10 | console.log("Working day"); 11 | break 12 | case "Saturday": 13 | case "Sunday": 14 | console.log("Weekend"); 15 | break 16 | default: 17 | console.log("Error"); 18 | break 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Conditional Statements Advanced - Lab/Working Hours.js: -------------------------------------------------------------------------------- 1 | function workingHours(input) { 2 | let hoursOfNight = Number(input[0]); 3 | let dayOfWeek = String(input[1]); 4 | 5 | 6 | if (hoursOfNight >= 10 && hoursOfNight < 18) { 7 | switch (dayOfWeek) { 8 | case "Monday": 9 | case "Tuesday": 10 | case "Wednesday": 11 | case "Thursday": 12 | case "Friday": 13 | case "Saturday": 14 | console.log("open"); break; 15 | // case "Sunday": console.log("closed"); break 16 | } 17 | 18 | } else { 19 | console.log("closed"); 20 | } 21 | 22 | 23 | } -------------------------------------------------------------------------------- /Conditional Statements Exercise/Bonus Score.js: -------------------------------------------------------------------------------- 1 | function bonusScore(input) { 2 | number = Number(input[0]); 3 | bonus = 0.0; 4 | 5 | if (number <= 100) { 6 | bonus = 5; 7 | } else if (number > 1000) { 8 | bonus = 0.10 * number; 9 | } else { 10 | bonus = 0.20 * number; 11 | } 12 | 13 | if (number % 2 === 0) { 14 | bonus += 1; 15 | } else if (number % 10 === 5) { 16 | bonus += 2; 17 | } 18 | console.log(bonus); 19 | console.log(number + bonus); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Conditional Statements Exercise/Godzilla Vs Kong.js: -------------------------------------------------------------------------------- 1 | function movie(input) { 2 | let budget = Number(input[0]); 3 | let countStatists = Number(input[1]); 4 | let priceClothing = Number(input[2]); // for one statists 5 | 6 | let sumScenery = budget * 0.1; 7 | let sumClothing = countStatists * priceClothing; 8 | 9 | if (countStatists > 150) { 10 | sumClothing *= 0.9; 11 | } 12 | 13 | let totalSumForMovie = sumScenery + sumClothing; 14 | 15 | if (totalSumForMovie > budget) { 16 | console.log("Not enough money!"); 17 | console.log(`Wingard needs ${(totalSumForMovie - budget).toFixed(2)} leva more.`); 18 | } else { 19 | console.log("Action!"); 20 | console.log(`Wingard starts filming with ${(budget - totalSumForMovie).toFixed(2)} leva left.`); 21 | 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Conditional Statements Exercise/Lunch Break.js: -------------------------------------------------------------------------------- 1 | function lunchBreak(Input) { 2 | let nameSerials = String(Input[0]); 3 | let countinueEpizode = Number(Input[1]); 4 | let countinueBreak = Number(Input[2]); 5 | 6 | let timeLunch = countinueBreak * 0.125; 7 | let timeRest = countinueBreak * 0.25; 8 | let leaveTime = countinueBreak - timeLunch - timeRest; 9 | 10 | if (leaveTime >= countinueEpizode) { 11 | console.log(`You have enough time to watch ${nameSerials} and left with ${Math.ceil(leaveTime - countinueEpizode)} minutes free time.`); 12 | } 13 | if (leaveTime < countinueEpizode) { 14 | console.log(`You don't have enough time to watch ${nameSerials}, you need ${Math.ceil(countinueEpizode - leaveTime)} more minutes.`) 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /Conditional Statements Exercise/Shopping.js: -------------------------------------------------------------------------------- 1 | function shopping(input) { 2 | let budget = Number(input[0]); 3 | let countVideocards = Number(input[1]); 4 | let countCPU = Number(input[2]); 5 | let countRAMMemory = Number(input[3]); 6 | 7 | let sumVideoCards = countVideocards * 250; 8 | let CUPprice = countCPU * (sumVideoCards * 0.35); 9 | let RAMprice = countRAMMemory * (sumVideoCards * 0.10); 10 | 11 | let totalSum = sumVideoCards + CUPprice + RAMprice; 12 | 13 | if (countVideocards > countCPU) { 14 | totalSum *= 0.85; 15 | } 16 | 17 | let difference = Math.abs(totalSum - budget); 18 | 19 | if (totalSum <= budget) { 20 | console.log(`You have ${difference.toFixed(2)} leva left!`); 21 | } else { 22 | console.log(`Not enough money! You need ${difference.toFixed(2)} leva more!`); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Conditional Statements Exercise/Sum Seconds.js: -------------------------------------------------------------------------------- 1 | function sum(input) { 2 | timeFirst = Number(input[0]); 3 | timeSecond = Number(input[1]); 4 | timeThird = Number(input[2]); 5 | 6 | let totalTime = timeFirst + timeSecond + timeThird; 7 | 8 | let minutes = Math.floor(totalTime / 60); 9 | let seconds = totalTime % 60; 10 | 11 | if (seconds < 10) { 12 | console.log(`${minutes}:0${seconds}`) 13 | } else { 14 | console.log(`${minutes}:${seconds}`); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Conditional Statements Exercise/Time 15 Minutes.js: -------------------------------------------------------------------------------- 1 | function time(input) { 2 | let h = Number(input[0]); 3 | let m = Number(input[1]); 4 | 5 | let time = h * 60 + m; // reverse hours in minutes 6 | time += 15; // add 15 minutes 7 | 8 | let hours = Math.floor(time / 60); // 1 hours = 60 min 9 | let minutes = time % 60; // give hours 10 | 11 | if (hours === 24) { 12 | hours = 0; 13 | } 14 | 15 | if (minutes < 10) { // lead 0 16 | console.log(`${hours}:0${minutes}`); 17 | 18 | } else { 19 | console.log(`${hours}:${minutes}`); 20 | } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Conditional Statements Exercise/Toy Shop.js: -------------------------------------------------------------------------------- 1 | function toyShop(input) { 2 | priceExcursion = Number(input[0]); 3 | countPuzzles = Number(input[1]); 4 | countTalkingDolls = Number(input[2]); 5 | countTeddyBears = Number(input[3]); 6 | countMinions = Number(input[4]); 7 | countTrucks = Number(input[5]); 8 | 9 | puzzle = 2.60; 10 | dolls = 3; 11 | bear = 4.10; 12 | minion = 8.20; 13 | truck = 2; 14 | 15 | let sum = (countPuzzles * puzzle) + (countTalkingDolls * dolls) + (countTeddyBears * bear) + 16 | (countMinions * minion) + (countTrucks * truck); 17 | 18 | let countToys = countPuzzles + countTalkingDolls + countTeddyBears + 19 | countMinions + countTrucks; 20 | 21 | if (countToys >= 50) { 22 | sum *= 0.75; 23 | } 24 | 25 | sum *= 0.90; 26 | 27 | let difference = Math.abs(priceExcursion - sum); 28 | 29 | if (priceExcursion <= sum) { 30 | console.log(`Yes! ${difference.toFixed(2)} lv left.`); 31 | } else { 32 | console.log(`Not enough money! ${difference.toFixed(2)} lv needed.`) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Conditional Statements Exercise/World Swimming Record.js: -------------------------------------------------------------------------------- 1 | function record(input) { 2 | let record = Number(input[0]); // in seconds // 3 | let distance = Number(input[1]); // in metres // 4 | let time = Number(input[2]); // in seconds // 5 | 6 | let timeIvan = distance * time; 7 | let delayTime = 12.5 * (Math.floor(distance / 15)); // about Ivan // 8 | let totalTime = timeIvan + delayTime; 9 | 10 | if (totalTime >= record) { 11 | console.log(`No, he failed! He was ${(totalTime - record).toFixed(2)} seconds slower.`); 12 | } 13 | 14 | if (totalTime < record) { 15 | console.log(`Yes, he succeeded! The new world record is ${(totalTime).toFixed(2)} seconds.`) 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Basketball Equipment.js: -------------------------------------------------------------------------------- 1 | function basketballEquipment(inpput) { 2 | yeardFee = Number(inpput[0]); // for basketball training // 3 | 4 | let priceSneakers = yeardFee - (0.4 * yeardFee); 5 | let priceTeam = priceSneakers - (0.2 * priceSneakers); 6 | let priceBall = 0.25 * priceTeam; 7 | let priceAccessories = 0.2 * priceBall; 8 | let totalPrice = yeardFee + priceSneakers + priceTeam + priceBall + priceAccessories; 9 | console.log(totalPrice); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Deposit Calculator.js: -------------------------------------------------------------------------------- 1 | function calculateOfDeposit(input) { 2 | let depositSum = Number(input[0]); 3 | let termOfDeposit = Number(input[1]); // mounth 4 | let yearPercentage = Number(input[2]); 5 | 6 | let interest = depositSum * (yearPercentage / 100); 7 | let interestForMounth = interest / 12; 8 | let totalSum = depositSum + termOfDeposit * interestForMounth; 9 | 10 | console.log(totalSum); 11 | } 12 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Fish Tank.js: -------------------------------------------------------------------------------- 1 | function fishAquarium(input) { 2 | length = Number(input[0]); 3 | width = Number(input[1]); 4 | height = Number(input[2]); 5 | percent = Number(input[3]); 6 | 7 | 8 | 9 | let volumeTank = length * width * height; 10 | let volumeLitre = volumeTank * 0.001; // volumeTank / 1 000 11 | let neededLitre = volumeLitre * (1 - (percent / 100)); 12 | console.log(neededLitre); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Food Delivery.js: -------------------------------------------------------------------------------- 1 | function foodDelivery(input) { 2 | countChikenMenu = Number(input[0]); 3 | countMenuFish = Number(input[1]); 4 | countVegetariansMenu = Number(input[2]); 5 | 6 | chikenMenu = 10.35; 7 | fishMenu = 12.40; 8 | vegetariansMenu = 8.15; 9 | discount = 2.50; 10 | 11 | let priceMenuChiken = countChikenMenu * chikenMenu; 12 | let priceMenuFish = countMenuFish * fishMenu; 13 | let priceMenuVegetarians = countVegetariansMenu * vegetariansMenu; 14 | 15 | let totalPriceMenu = priceMenuChiken + priceMenuFish + priceMenuVegetarians; 16 | let priceDessert = (20 / 100) * totalPriceMenu; 17 | let TotalPriceOrdered = totalPriceMenu + priceDessert + discount; 18 | console.log(`${TotalPriceOrdered}`); 19 | } 20 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Radians to Degrees.js: -------------------------------------------------------------------------------- 1 | function conventor(input) { 2 | let radians = Number(input[0]); 3 | 4 | let degrees = radians * 180 / Math.PI; 5 | console.log(degrees); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Repainting.js: -------------------------------------------------------------------------------- 1 | function repainting(input) { 2 | neededNylon = Number(input[0]); 3 | neededDye = Number(input[1]); 4 | quantityThinner = Number(input[2]); 5 | hours = Number(input[3]); 6 | 7 | nylon = 1.50; 8 | dye = 14.50; 9 | thinner = 5; 10 | bags = 0.40; 11 | 12 | let priceNylon = (neededNylon + 2) * nylon; 13 | let priceDye = (neededDye + (0.1 * neededDye)) * dye; 14 | let priceThinner = quantityThinner * thinner; 15 | 16 | let totalSum = priceNylon + priceDye + priceThinner + bags; 17 | let sumMasters = (totalSum * (30 / 100)) * hours; 18 | let finalSum = totalSum + sumMasters; 19 | console.log(finalSum); 20 | } 21 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Supplies for School.js: -------------------------------------------------------------------------------- 1 | function suppliesForSchool(input) { 2 | countPensils = Number(input[0]); 3 | countMarkers = Number(input[1]); 4 | litresPreparation = Number(input[2]); // for cleaning the board // 5 | percent = Number(input[3]); // discount // 6 | 7 | pencils = 5.80; 8 | markers = 7.20; 9 | preparation = 1.20; // for litre // 10 | 11 | let pricePencils = countPensils * pencils; 12 | let priceMarkers = countMarkers * markers; 13 | let pricePreparation = litresPreparation * preparation; 14 | let priceTotalMaterials = pricePencils + priceMarkers + pricePreparation; 15 | let priceDiscount = priceTotalMaterials - (priceTotalMaterials * (percent / 100)); 16 | console.log(priceDiscount); 17 | } 18 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/USD to BGN.js: -------------------------------------------------------------------------------- 1 | function conventor(input) { 2 | let usd = Number(input[0]); 3 | let bgn = usd * 1.79549; 4 | console.log(bgn); 5 | } 6 | -------------------------------------------------------------------------------- /First steps in coding - Exercise/Vacation Books List.js: -------------------------------------------------------------------------------- 1 | function vacationBooksList(input) { 2 | let countPages = Number(input[0]); // current book 3 | let pages = Number(input[1]); // read for 1 hour 4 | let countDays = Number(input[2]); // for read a book 5 | 6 | let totalTime = countPages / pages; 7 | let neededHours = totalTime / countDays // hour on day 8 | console.log(neededHours); 9 | } 10 | -------------------------------------------------------------------------------- /First steps in coding -Lab/Concatenate Data.js: -------------------------------------------------------------------------------- 1 | function concatenateDate(input) { 2 | let firstName = String(input[0]); 3 | let lastName = String(input[1]); 4 | let age = Number(input[2]); 5 | let town = String(input[3]); 6 | 7 | console.log(`You are ${firstName} ${lastName}, a ${age}-years old person from ${town}.`); 8 | } 9 | -------------------------------------------------------------------------------- /First steps in coding -Lab/Greeting by Name.js: -------------------------------------------------------------------------------- 1 | function greeting(input) { 2 | let name = String(input[0]); 3 | console.log(`Hello, ${name}!`); 4 | } 5 | -------------------------------------------------------------------------------- /First steps in coding -Lab/Hello SoftUni.js: -------------------------------------------------------------------------------- 1 | function hello() { 2 | console.log("Hello Softuni"); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /First steps in coding -Lab/Inches to Centimeters.js: -------------------------------------------------------------------------------- 1 | function inchesToCentimetres(input) { 2 | let number = Number(input[0]); 3 | let centimetres = 2.54; 4 | 5 | let rezult = number * centimetres; 6 | console.log(rezult); 7 | } 8 | -------------------------------------------------------------------------------- /First steps in coding -Lab/Nums 1 to 10.js: -------------------------------------------------------------------------------- 1 | function nums() { 2 | console.log(1); 3 | console.log(2); 4 | console.log(3); 5 | console.log(4); 6 | console.log(5); 7 | console.log(6); 8 | console.log(7); 9 | console.log(8); 10 | console.log(9); 11 | console.log(10); 12 | } 13 | 14 | 15 | /*function num(){ 16 | for(let i = 1; i <=10; i+=1){ 17 | console.log(i); 18 | } 19 | } 20 | num(); 21 | */ -------------------------------------------------------------------------------- /First steps in coding -Lab/Pet Shop.js: -------------------------------------------------------------------------------- 1 | function petShop(input) { 2 | let countDogsFood = Number(input[0]); 3 | let countCatsFood = Number(input[1]); 4 | 5 | let priceDogsFood = 2.50; 6 | let priceCatsFood = 4; 7 | let DogsFood = countDogsFood * priceDogsFood; 8 | let CatsFood = countCatsFood * priceCatsFood; 9 | let neededMoney = DogsFood + CatsFood; 10 | console.log(`${neededMoney}.lv`); 11 | } -------------------------------------------------------------------------------- /First steps in coding -Lab/Square Area.js: -------------------------------------------------------------------------------- 1 | function number(input) { 2 | let num = Number(input[0]); 3 | let area = num * num; 4 | console.log(area); 5 | } 6 | -------------------------------------------------------------------------------- /First steps in coding -Lab/Yard Greening.js: -------------------------------------------------------------------------------- 1 | function neededSum(input) { 2 | let metresYardGreening = Number(input[0]); 3 | 4 | let wholeYard = metresYardGreening * 7.61 // 7.61 - price for 1 square meter 5 | let discount = 0.18 * wholeYard; 6 | let finalPrice = wholeYard - discount; 7 | 8 | console.log(`The final price is: ${finalPrice} lv.`); 9 | console.log(`The discount is: ${discount} lv.`); 10 | } 11 | -------------------------------------------------------------------------------- /For Loop - Exercise/Clever Lily.js: -------------------------------------------------------------------------------- 1 | function cleverLily(input) { 2 | let ages = Number(input[0]); 3 | let priceWashingMachine = Number(input[1]); 4 | let singlePriceToy = Number(input[2]); 5 | 6 | let toys = 0; // receive toys 7 | let evenBirthday = 0; // receive money 8 | let totalMoney = 0; 9 | let totalSum = 0; 10 | 11 | for (let i = 1; i <= ages; i++) { 12 | if (i % 2 === 0) { 13 | evenBirthday++; 14 | totalSum = evenBirthday * 10 - 1; 15 | totalMoney += totalSum; 16 | } else { 17 | toys++; 18 | } 19 | } 20 | totalMoney += singlePriceToy * toys; 21 | 22 | if (totalMoney >= priceWashingMachine) { 23 | console.log(`Yes! ${(totalMoney - priceWashingMachine).toFixed(2)}`); 24 | } else { 25 | console.log(`No! ${(priceWashingMachine - totalMoney).toFixed(2)}`); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /For Loop - Exercise/Histogram.js: -------------------------------------------------------------------------------- 1 | function histograma(input) { 2 | let number = Number(input[0]); 3 | 4 | let p1 = 0; 5 | let p2 = 0; 6 | let p3 = 0; 7 | let p4 = 0; 8 | let p5 = 0; 9 | 10 | let p1Percentage = 0; 11 | let p2Percentage = 0; 12 | let p3Percentage = 0; 13 | let p4Percentage = 0; 14 | let p5Percentage = 0; 15 | 16 | for (i = 1; i <= number; i++) { 17 | let currentNumber = Number(input[i]); 18 | 19 | if (currentNumber < 200) { 20 | p1++; 21 | } else if (currentNumber >= 200 && currentNumber <= 399) { 22 | p2++; 23 | } else if (currentNumber >= 400 && currentNumber <= 599) { 24 | p3++; 25 | } else if (currentNumber >= 600 && currentNumber <= 799) { 26 | p4++; 27 | } else { 28 | p5++; 29 | } 30 | 31 | p1Percentage = ((p1 / number) * 100).toFixed(2); 32 | p2Percentage = ((p2 / number) * 100).toFixed(2); 33 | p3Percentage = ((p3 / number) * 100).toFixed(2); 34 | p4Percentage = ((p4 / number) * 100).toFixed(2); 35 | p5Percentage = ((p5 / number) * 100).toFixed(2); 36 | } 37 | 38 | console.log(p1Percentage + "%"); 39 | console.log(p2Percentage + "%"); 40 | console.log(p3Percentage + "%"); 41 | console.log(p4Percentage + "%"); 42 | console.log(p5Percentage + "%"); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /For Loop - Exercise/Multiplication Table.js: -------------------------------------------------------------------------------- 1 | function multiplicationTable(input) { 2 | let number = Number(input[0]); 3 | for (let i = 1; i <= 10; i++) { 4 | console.log(`${i} * ${number} = ${i * number}`); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /For Loop - Exercise/Numbers 1000, ending in 7.js: -------------------------------------------------------------------------------- 1 | function numbersEnding7() { 2 | for (let i = 7; i <= 1000; i++) { 3 | if (i % 10 === 7) { 4 | console.log(i); 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /For Loop - Exercise/Oscars.js: -------------------------------------------------------------------------------- 1 | function oscars(input) { 2 | let nameActor = String(input[0]); 3 | let scoreAcademy = Number(input[1]); 4 | let countJudge = Number(input[2]); 5 | 6 | let totalScore = 0; 7 | 8 | for (let i = 3; i < countJudge * 2 + 3; i += 2) { 9 | let nameJudge = String(input[i]); 10 | let scoreJudge = Number(input[i + 1]); 11 | 12 | totalScore += (scoreJudge * nameJudge.length) / 2; 13 | 14 | if (totalScore + scoreAcademy > 1250.5) { 15 | console.log(`Congratulations, ${nameActor} got a nominee for leading role with ${(totalScore + scoreAcademy).toFixed(1)}!`); 16 | break; 17 | } 18 | } 19 | 20 | if (totalScore + scoreAcademy <= 1250.5) { 21 | console.log(`Sorry, ${nameActor} you need ${(1250.5 - (scoreAcademy + totalScore)).toFixed(1)} more!`); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /For Loop - Exercise/Salary.js: -------------------------------------------------------------------------------- 1 | function salary(input) { 2 | let countOpenTabs = Number(input[0]); 3 | let salary = Number(input[1]); 4 | 5 | for (let i = 1; i <= countOpenTabs + 1; i++) { 6 | let nameOfWebsites = String(input[i]); 7 | 8 | switch (nameOfWebsites) { 9 | case "Facebook": 10 | salary -= 150; 11 | break; 12 | case "Instagram": 13 | salary -= 100; 14 | break; 15 | case "Reddit": 16 | salary -= 50; 17 | break; 18 | } 19 | 20 | if (salary <= 0) { 21 | console.log("You have lost your salary."); 22 | break; 23 | } 24 | } 25 | 26 | if (salary > 0) { 27 | console.log(salary); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /For Loop - Exercise/Tennis Ranklist.js: -------------------------------------------------------------------------------- 1 | function tennis(input) { 2 | let countTournaments = Number(input[0]); 3 | let stratScore = Number(input[1]); 4 | 5 | let score = 0; 6 | let totalScore = 0; 7 | 8 | let winTournaments = 0; 9 | 10 | 11 | for (let i = 2; i < countTournaments + 2; i++) { 12 | let stageTournaments = String(input[i]); 13 | 14 | switch (stageTournaments) { 15 | case "W": score += 2000; winTournaments++; break; 16 | case "F": score += 1200; break 17 | case "SF": score += 720; break; 18 | } 19 | 20 | } 21 | totalScore = stratScore + score; 22 | console.log(`Final points: ${totalScore}`); 23 | console.log(`Average points: ${Math.floor(score / countTournaments)}`); 24 | console.log(`${((winTournaments / countTournaments) * 100).toFixed(2)}%`); 25 | } 26 | -------------------------------------------------------------------------------- /For Loop - Exercise/Trekking Mania.js: -------------------------------------------------------------------------------- 1 | function mania(input) { 2 | let countOfGroup = Number(input[0]); 3 | 4 | let topMusala = 0; 5 | let topMonblan = 0; 6 | let topKlimandjaro = 0; 7 | let topK2 = 0; 8 | let topEverest = 0; 9 | 10 | let totalCountPeople = 0; 11 | 12 | for (let i = 1; i < countOfGroup + 1; i++) { 13 | let countPeople = Number(input[i]); 14 | 15 | if (countPeople <= 5) { 16 | topMusala += countPeople; 17 | } else if (countPeople <= 12 && countPeople > 5) { 18 | topMonblan += countPeople; 19 | } else if (countPeople <= 25 && countPeople > 12) { 20 | topKlimandjaro += countPeople; 21 | } else if (countPeople <= 40 && countPeople > 25) { 22 | topK2 += countPeople; 23 | } else if (countPeople >= 41) { 24 | topEverest += countPeople; 25 | } 26 | 27 | totalCountPeople += countPeople; 28 | } 29 | 30 | console.log(`${((topMusala / totalCountPeople) * 100).toFixed(2)}%`); 31 | console.log(`${((topMonblan / totalCountPeople) * 100).toFixed(2)}%`); 32 | console.log(`${((topKlimandjaro / totalCountPeople) * 100).toFixed(2)}%`); 33 | console.log(`${((topK2 / totalCountPeople) * 100).toFixed(2)}%`); 34 | console.log(`${((topEverest / totalCountPeople) * 100).toFixed(2)}%`); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /For Loop - Lab/Character Sequence.js: -------------------------------------------------------------------------------- 1 | function character(input) { 2 | let text = String(input[0]); 3 | 4 | for (let i = 0; i < text.length; i++) { 5 | let letter = text[i]; 6 | console.log(letter); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /For Loop - Lab/Even Powers of 2.js: -------------------------------------------------------------------------------- 1 | function evenNumbersOf2(input) { 2 | let n = Number(input[0]); 3 | 4 | for (let i = 0; i <= n; i += 2) { 5 | console.log(Math.pow(2, i)); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /For Loop - Lab/Numbers Divisible by 9.js: -------------------------------------------------------------------------------- 1 | function numbersDivisibleBy9(input) { 2 | let firstNumber = Number(input[0]); 3 | let secondNumber = Number(input[1]); 4 | 5 | let sum = 0; 6 | 7 | for (let i = firstNumber; i < secondNumber; i++) { 8 | if (i % 9 === 0) { 9 | sum += i; 10 | 11 | } 12 | } 13 | console.log(`The sum: ${sum}`); 14 | 15 | for (let j = firstNumber; j < secondNumber; j++) { 16 | if (j % 9 === 0) { 17 | console.log(j); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /For Loop - Lab/Numbers 1 N with Step 3.js: -------------------------------------------------------------------------------- 1 | function numbers1ToStep3(input) { 2 | let n = Number(input[0]); 3 | 4 | for (let i = 1; i <= n; i += 3) { 5 | console.log(i); 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /For Loop - Lab/Numbers N to 1.js: -------------------------------------------------------------------------------- 1 | function numberNTo1(input) { 2 | let n = Number(input[0]); 3 | 4 | for (let i = n; i > 0; i--) { 5 | console.log(i) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /For Loop - Lab/Numbers from 1 to 100.js: -------------------------------------------------------------------------------- 1 | function numbersFrom1To100() { 2 | for (let i = 1; i <= 100; i++) { 3 | console.log(i) 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /For Loop - Lab/Sum of Numbers.js: -------------------------------------------------------------------------------- 1 | function sumOfNumbers(input) { 2 | let n = String(input[0]); 3 | 4 | let sum = 0; 5 | 6 | for (let i = 0; i < n.length; i++) { 7 | let currentNumber = Number(n[i]); 8 | sum += currentNumber; 9 | } 10 | console.log(`The sum of the digits is:${sum}`); 11 | } 12 | -------------------------------------------------------------------------------- /For Loop - Lab/Vowels Sum.js: -------------------------------------------------------------------------------- 1 | function vowelsSum(input) { 2 | let vowels = String(input[0]); 3 | 4 | let sum = 0; 5 | 6 | for (let i = 0; i < vowels.length; i++) { 7 | let letter = vowels.charAt(i); 8 | 9 | switch (letter) { 10 | case "a": sum += 1; break; 11 | case "e": sum += 2; break; 12 | case "i": sum += 3; break; 13 | case "o": sum += 4; break; 14 | case "u": sum += 5; break; 15 | } 16 | } 17 | console.log(sum) 18 | } 19 | 20 | 21 | 22 | // function vowelsSum(input) { 23 | // let vowels = String(input[0]); 24 | // let sum = 0; 25 | 26 | // for (let i = 0; i < vowels.length; i++) { 27 | // let letter = vowels.charAt(i); 28 | 29 | // if (letter === "a") { 30 | // sum += 1; 31 | // } 32 | 33 | // if (letter === "e") { 34 | // sum += 2; 35 | // } 36 | 37 | // if (letter === "i") { 38 | // sum += 3; 39 | // } 40 | 41 | // if (letter === "o") { 42 | // sum += 4; 43 | // } 44 | 45 | // if (letter === "u") { 46 | // sum += 5; 47 | // } 48 | // } 49 | // console.log(sum); 50 | // } 51 | 52 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/Back To The Past.js: -------------------------------------------------------------------------------- 1 | function backToThePast(input) { 2 | let inheritedMoney = Number(input[0]); 3 | let includedYear = Number(input[1]); 4 | 5 | let hisAge = 18; 6 | let backYear = 1800; 7 | let evenYear = 12000; 8 | 9 | for (let i = backYear; backYear <= includedYear; backYear++) { 10 | let oddYear = 12000 + 50 * hisAge; 11 | if (backYear % 2 === 0) { 12 | inheritedMoney -= evenYear; 13 | } else { 14 | inheritedMoney -= oddYear; 15 | } 16 | 17 | hisAge++ 18 | } 19 | 20 | if (inheritedMoney >= 0) { 21 | console.log(`Yes! He will live a carefree life and will have ${inheritedMoney.toFixed(2)} dollars left.`); 22 | } else { 23 | console.log(`He will need ${Math.abs(inheritedMoney).toFixed(2)} dollars to survive.`); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/Bills.js: -------------------------------------------------------------------------------- 1 | function bills(input) { 2 | let months = Number(input[0]); 3 | 4 | let water = 20; 5 | let internetBill = 15; 6 | let other = 0; 7 | 8 | let waterPrice = 0; 9 | let internetPrice = 0; 10 | let electricityPrice = 0; 11 | let otherPrice = 0; 12 | let average = 0; 13 | 14 | for (let i = 1; i <= months; i++) { 15 | let electricityBill = Number(input[i]); 16 | electricityPrice += electricityBill; 17 | waterPrice = water * months; 18 | internetPrice = internetBill * months; 19 | other = (electricityBill + water + internetBill) * 1.2; 20 | otherPrice += other; 21 | } 22 | average = 23 | (electricityPrice + waterPrice + internetPrice + otherPrice) / months; 24 | console.log(`Electricity: ${electricityPrice.toFixed(2)} lv`); 25 | console.log(`Water: ${waterPrice.toFixed(2)} lv`); 26 | console.log(`Internet: ${internetPrice.toFixed(2)} lv`); 27 | console.log(`Other: ${otherPrice.toFixed(2)} lv`); 28 | console.log(`Average: ${average.toFixed(2)} lv`); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/Equal Pairs.js: -------------------------------------------------------------------------------- 1 | function equalPairs(input) { 2 | index = 0; 3 | const numberOfPairs = Number(input[index++]); 4 | let firstNum = 0; 5 | let secondNum = 0; 6 | let sum = 0; 7 | let diff = 0; 8 | let valueMin = 100; 9 | let valueMax = -100; 10 | let max1 = 0; 11 | let min1 = 0; 12 | 13 | for (let i = 0; i < numberOfPairs; i++) { 14 | firstNum = Number(input[index++]); 15 | secondNum = Number(input[index++]); 16 | sum = firstNum + secondNum; 17 | 18 | if (sum > valueMax) { 19 | valueMax = sum; 20 | } else if (sum < valueMax) { 21 | max1 = sum; 22 | } 23 | 24 | if (sum < valueMin) { 25 | valueMin = sum; 26 | } else if (sum > valueMin) { 27 | min1 = sum; 28 | } 29 | } 30 | 31 | diff = Math.abs(valueMin - valueMax); 32 | let diff2 = Math.abs(min1 - max1); 33 | if (valueMin === valueMax) { 34 | console.log(`Yes, value=${valueMin}`); 35 | } else { 36 | if (diff > diff2 && numberOfPairs > 3) { 37 | console.log(`No, maxdiff=${diff2}`); 38 | } else { 39 | console.log(`No, maxdiff=${diff}`); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /For-Loop - More Exercises/Football Legue.js: -------------------------------------------------------------------------------- 1 | function footballLegue(input) { 2 | let capacityStadium = Number(input[0]); 3 | let countFans = Number(input[1]); 4 | 5 | let percentageA = 0; 6 | let percentageB = 0; 7 | let percentageV = 0; 8 | let percentageG = 0; 9 | let percentageFans = 0; //according to the capacity of the stadium 10 | 11 | let sectorA = 0; 12 | let sectorB = 0; 13 | let sectorV = 0; 14 | let sectorG = 0; 15 | 16 | for (i = 2; i <= capacityStadium + 2; i++) { 17 | let sector = String(input[i]); 18 | if (sector === "A") { 19 | sectorA++; 20 | percentageA = (sectorA / countFans) * 100; 21 | } else if (sector === "B") { 22 | sectorB++; 23 | percentageB = (sectorB / countFans) * 100; 24 | } else if (sector === "V") { 25 | sectorV++; 26 | percentageV = (sectorV / countFans) * 100; 27 | } else if (sector === "G") { 28 | sectorG++; 29 | percentageG = (sectorG / countFans) * 100; 30 | } 31 | } 32 | percentageFans = (countFans / capacityStadium) * 100; 33 | 34 | console.log(`${percentageA.toFixed(2)}%`); 35 | console.log(`${percentageB.toFixed(2)}%`); 36 | console.log(`${percentageV.toFixed(2)}%`); 37 | console.log(`${percentageG.toFixed(2)}%`); 38 | console.log(`${percentageFans.toFixed(2)}%`); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/Game Of Intervals.js: -------------------------------------------------------------------------------- 1 | function gameOfIntervals(input) { 2 | let courses = Number(input[0]); 3 | 4 | let finalResult = 0; 5 | let zeroToNine = 0; 6 | let tenToNineteen = 0; 7 | let twentyToTwentyNine = 0; 8 | let thirtyToThyrtyNine = 0; 9 | let fortyToFifty = 0; 10 | let invalidNumbers = 0; 11 | 12 | //let score = 0; 13 | 14 | for (let i = 1; i <= courses; i++) { 15 | let coursesNumber = Number(input[i]); 16 | 17 | if (coursesNumber >= 0 && coursesNumber <= 9) { 18 | zeroToNine++; 19 | finalResult += coursesNumber * 0.2; 20 | } else if (coursesNumber >= 10 && coursesNumber <= 19) { 21 | tenToNineteen++; 22 | finalResult += coursesNumber * 0.3; 23 | } else if (coursesNumber >= 20 && coursesNumber <= 29) { 24 | twentyToTwentyNine++; 25 | finalResult += coursesNumber * 0.4; 26 | } else if (coursesNumber >= 30 && coursesNumber <= 39) { 27 | thirtyToThyrtyNine++; 28 | finalResult += 50; 29 | } else if (coursesNumber >= 40 && coursesNumber <= 50) { 30 | fortyToFifty++; 31 | finalResult += 100; 32 | } else { 33 | invalidNumbers++; 34 | finalResult /= 2; 35 | } 36 | } 37 | console.log(`${finalResult.toFixed(2)}`); 38 | console.log(`From 0 to 9: ${((zeroToNine / courses) * 100).toFixed(2)}%`); 39 | console.log( 40 | `From 10 to 19: ${((tenToNineteen / courses) * 100).toFixed(2)}%` 41 | ); 42 | console.log( 43 | `From 20 to 29: ${((twentyToTwentyNine / courses) * 100).toFixed(2)}%` 44 | ); 45 | console.log( 46 | `From 30 to 39: ${((thirtyToThyrtyNine / courses) * 100).toFixed(2)}%` 47 | ); 48 | console.log(`From 40 to 50: ${((fortyToFifty / courses) * 100).toFixed(2)}%`); 49 | console.log( 50 | `Invalid numbers: ${((invalidNumbers / courses) * 100).toFixed(2)}%` 51 | ); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/Grades.js: -------------------------------------------------------------------------------- 1 | function grades(input) { 2 | let countStudents = Number(input[0]); 3 | 4 | let topStudents = 0; 5 | let goodGrade = 0; 6 | let middleGrade = 0; 7 | let poorGrade = 0; 8 | let avarageGrade = 0; 9 | 10 | for (let i = 1; i < countStudents + 1; i++) { 11 | let gradeOfExam = Number(input[i]); 12 | if (gradeOfExam <= 2.99) { 13 | poorGrade++; 14 | } 15 | if (gradeOfExam >= 3 && gradeOfExam <= 3.99) { 16 | middleGrade++; 17 | } 18 | if (gradeOfExam >= 4 && gradeOfExam <= 4.99) { 19 | goodGrade++; 20 | } 21 | if (gradeOfExam >= 5) { 22 | topStudents++; 23 | } 24 | avarageGrade += gradeOfExam; 25 | 26 | } 27 | 28 | console.log(`Top students: ${((topStudents / countStudents) * 100).toFixed(2)}%`); 29 | console.log(`Between 4.00 and 4.99: ${((goodGrade / countStudents) * 100).toFixed(2)}%`); 30 | console.log(`Between 3.00 and 3.99: ${((middleGrade / countStudents) * 100).toFixed(2)}%`); 31 | console.log(`Fail: ${((poorGrade / countStudents) * 100).toFixed(2)}%`); 32 | console.log(`Average: ${(avarageGrade / countStudents).toFixed(2)}`); 33 | } 34 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/Hospital.js: -------------------------------------------------------------------------------- 1 | function hospital(input) { 2 | let term = Number(input[0]); 3 | 4 | let doctors = 7; 5 | 6 | 7 | let treatedPatients = 0; 8 | let untreatedPatients = 0; 9 | 10 | for (let i = 1; i < term + 1; i++) { 11 | let countPatients = Number(input[i]); 12 | if (i % 3 === 0) { 13 | if (treatedPatients < untreatedPatients) { 14 | doctors++; 15 | } 16 | } 17 | if (countPatients >= doctors) { 18 | treatedPatients += doctors; 19 | untreatedPatients += countPatients - doctors; 20 | 21 | } else { 22 | treatedPatients += countPatients; 23 | } 24 | 25 | } 26 | 27 | console.log(`Treated patients: ${treatedPatients}.`); 28 | console.log(`Untreated patients: ${untreatedPatients}.`); 29 | } 30 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/Logistics.js: -------------------------------------------------------------------------------- 1 | function logistics(input) { 2 | let countFreight = Number(input[0]); 3 | 4 | 5 | let averageFreight = 0; 6 | 7 | 8 | let minibusTone = 0; 9 | let truckTone = 0; 10 | let trainTone = 0; 11 | 12 | let minibusPrice = 0; 13 | let truckPrice = 0; 14 | let trainPrice = 0; 15 | 16 | let totalTone = 0; 17 | 18 | 19 | for (let i = 1; i < countFreight + 1; i++) { 20 | let cargoTonnage = Number(input[i]); 21 | 22 | if (cargoTonnage <= 3) { 23 | minibusTone += cargoTonnage; 24 | minibusPrice += cargoTonnage * 200; 25 | } 26 | if (cargoTonnage > 3 && cargoTonnage <= 11) { 27 | truckTone += cargoTonnage; 28 | truckPrice += cargoTonnage * 175; 29 | } 30 | if (cargoTonnage >= 12) { 31 | trainTone += cargoTonnage; 32 | trainPrice += cargoTonnage * 120; 33 | } 34 | 35 | 36 | totalTone += cargoTonnage; 37 | } 38 | 39 | averageFreight = (minibusPrice + truckPrice + trainPrice) / totalTone; 40 | 41 | 42 | 43 | console.log(averageFreight.toFixed(2)); 44 | console.log(`${(minibusTone / totalTone * 100).toFixed(2)}%`); 45 | console.log(`${(truckTone / totalTone * 100).toFixed(2)}%`); 46 | console.log(`${(trainTone / totalTone * 100).toFixed(2)}%`); 47 | } 48 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/clock.js: -------------------------------------------------------------------------------- 1 | function clockPartTwo() { 2 | for (hours = 0; hours <= 23; hours++) { 3 | for (minutes = 0; minutes <= 59; minutes++) { 4 | //console.log(`${hours} : ${minutes}`); 5 | for (let seconds = 0; seconds <= 59; seconds++) { 6 | console.log(`${hours} : ${minutes} : ${seconds}`); 7 | } 8 | } 9 | 10 | 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/clockPart 2.js: -------------------------------------------------------------------------------- 1 | function clockPartTwo() { 2 | for (hours = 0; hours <= 23; hours++) { 3 | for (minutes = 0; minutes <= 59; minutes++) { 4 | //console.log(`${hours} : ${minutes}`); 5 | for (let seconds = 0; seconds <= 59; seconds++) { 6 | console.log(`${hours} : ${minutes} : ${seconds}`); 7 | } 8 | } 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /For-Loop - More Exercises/footballLegue2.js: -------------------------------------------------------------------------------- 1 | function footballLegue2(input) { 2 | let capacityStadium = Number(input[0]); 3 | let countFans = Number(input[1]); 4 | 5 | let percentageA = 0; 6 | let percentageB = 0; 7 | let percentageV = 0; 8 | let percentageG = 0; 9 | let percentageFans = 0; //according to the capacity of the stadium 10 | 11 | let sectorA = 0; 12 | let sectorB = 0; 13 | let sectorV = 0; 14 | let sectorG = 0; 15 | for (i = 2; i <= capacityStadium + 2; i++) { 16 | let sector = String(input[i]); 17 | switch (sector) { 18 | case "A": 19 | sectorA++; 20 | percentageA = (sectorA / countFans) * 100; 21 | break; 22 | case "B": 23 | sectorB++; 24 | percentageB = (sectorB / countFans) * 100; 25 | break; 26 | case "V": 27 | sectorV++; 28 | percentageV = (sectorV / countFans) * 100; 29 | break; 30 | case "G": 31 | sectorG++; 32 | percentageG = (sectorG / countFans) * 100; 33 | break; 34 | } 35 | } 36 | percentageFans = (countFans / capacityStadium) * 100; 37 | 38 | console.log(`${percentageA.toFixed(2)}%`); 39 | console.log(`${percentageB.toFixed(2)}%`); 40 | console.log(`${percentageV.toFixed(2)}%`); 41 | console.log(`${percentageG.toFixed(2)}%`); 42 | console.log(`${percentageFans.toFixed(2)}%`); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Nested Loops - Exercise/Cinema Tickets.js: -------------------------------------------------------------------------------- 1 | function cinemaTickets(input) { 2 | let index = 0; 3 | 4 | let command = input[index]; 5 | index += 1; 6 | 7 | let studentTicket = 0; 8 | let standardTicket = 0; 9 | let kidTicket = 0; 10 | let ticketCounter = 0; 11 | 12 | while (command !== "Finish") { 13 | let name = command; 14 | let freeSpace = Number(input[index]); 15 | index += 1; 16 | 17 | let type = input[index]; 18 | index += 1; 19 | 20 | let tempTicket = 0; 21 | while (type !== "End") { 22 | switch (type) { 23 | case "student": studentTicket += 1; break; 24 | case "standard": standardTicket += 1; break; 25 | case "kid": kidTicket += 1; break; 26 | } 27 | tempTicket += 1; 28 | 29 | if (tempTicket >= freeSpace) { 30 | break; 31 | } 32 | type = input[index]; 33 | index += 1; 34 | } 35 | 36 | let capacity = tempTicket / freeSpace * 100; 37 | console.log(`${name} - ${(capacity).toFixed(2)}% full.`); 38 | ticketCounter += tempTicket; 39 | command = input[index]; 40 | index += 1; 41 | } 42 | let studentPercentage = studentTicket / ticketCounter * 100; 43 | let standardPercentage = standardTicket / ticketCounter * 100; 44 | let kidPercentage = kidTicket / ticketCounter * 100; 45 | 46 | console.log(`Total tickets: ${ticketCounter}`); 47 | 48 | console.log(`${(studentPercentage).toFixed(2)}% student tickets.`); 49 | console.log(`${(standardPercentage).toFixed(2)}% standard tickets.`); 50 | console.log(`${(kidPercentage).toFixed(2)}% kids tickets.`); 51 | 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /Nested Loops - Exercise/Equal Sums Even Odd Position.js: -------------------------------------------------------------------------------- 1 | function equalSums(input) { 2 | let firstNum = Number(input[0]); 3 | let secondNum = Number(input[1]); 4 | let printLine = ' '; 5 | for (let i = firstNum; i <= secondNum; i += 1) { 6 | let currentNum = " " + i; 7 | let oddSum = 0; 8 | let evenSum = 0; 9 | for (let j = 0; j < currentNum.length; j += 1) { 10 | let currentDigit = Number(currentNum.charAt(j)); 11 | if (j % 2 === 0) { 12 | evenSum += currentDigit; 13 | } else { 14 | oddSum += currentDigit; 15 | } 16 | } 17 | if (oddSum === evenSum) { 18 | printLine += `${i} `; 19 | } 20 | } 21 | console.log(printLine); 22 | } 23 | -------------------------------------------------------------------------------- /Nested Loops - Exercise/Number Pyramid.js: -------------------------------------------------------------------------------- 1 | function numberPyramid(input) { 2 | let n = Number(input[0]); 3 | 4 | let cuurent = 1; 5 | let isBigger = false; 6 | let printCurrentLine = " "; 7 | for (let rows = 1; rows <= n; rows += 1) { 8 | for (let colums = 1; colums <= rows; colums += 1) { 9 | if (cuurent > n) { 10 | isBigger = true; 11 | break; 12 | } 13 | printCurrentLine += cuurent + " "; 14 | cuurent += 1; 15 | } 16 | console.log(printCurrentLine); 17 | printCurrentLine = " "; 18 | if (isBigger) { 19 | break; 20 | } 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Nested Loops - Exercise/Special Numbers.js: -------------------------------------------------------------------------------- 1 | function specialNumber(input) { 2 | let n = input[0]; 3 | let index = "" 4 | //const sn = [] 5 | for (let i = 1111; i < 10000; i += 1) { 6 | tex = String(i) 7 | for (let j = 0; j < tex.length; j += 1) { 8 | if (n % Number(tex[j]) === 0) { 9 | if (n % Number(tex[j + 1]) === 0) { 10 | if (n % Number(tex[j + 2]) === 0) { 11 | if (n % Number(tex[j + 3]) === 0) { 12 | //sn[index] = Number(tex); 13 | index += i + j + " "; 14 | //console.log(tex); 15 | } 16 | } 17 | } 18 | } 19 | } 20 | } 21 | console.log(index); 22 | } 23 | -------------------------------------------------------------------------------- /Nested Loops - Exercise/Sum Prime Non Prime.js: -------------------------------------------------------------------------------- 1 | function sumPrimeNonPrime(input) { 2 | let command = String(input[0]); 3 | let index = 0; 4 | 5 | let sumPrime = 0; 6 | let sumNonPrime = 0; 7 | let prime = 0; 8 | 9 | while (command !== "stop") { 10 | command = Math.trunc(Number(input[index])); 11 | if (command < 0) { 12 | console.log("Number is negative."); 13 | } else { 14 | if (command === 0) { 15 | sumNonPrime += command; 16 | } 17 | if (command === 1) { 18 | sumNonPrime += command; 19 | } 20 | if (command === 2) { 21 | sumPrime += command 22 | } 23 | if (command > 2) { 24 | prime = (Math.pow(2, command) - 2) / command; 25 | if (prime % 2 === 0) { 26 | sumPrime += command; 27 | } else { 28 | sumNonPrime += command; 29 | } 30 | } 31 | } 32 | index += 1; 33 | command = input[index]; 34 | } 35 | console.log(`Sum of all prime numbers is: ${sumPrime}`); 36 | console.log(`Sum of all non prime numbers is: ${sumNonPrime}`); 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /Nested Loops - Exercise/Train The Trainers.js: -------------------------------------------------------------------------------- 1 | function trainTheTrainers(input) { 2 | let index = 0; 3 | let people = Number(input[index]); 4 | index += 1; 5 | let command = input[index]; 6 | index += 1; 7 | 8 | let counter = 0; 9 | let sumGrade = 0; 10 | 11 | while (command !== "Finish") { 12 | let name = command; 13 | counter += 1; 14 | let TotalGrade = 0; 15 | for (let i = 0; i < people; i += 1) { 16 | let grade = Number(input[index]); 17 | index += 1; 18 | TotalGrade += grade; 19 | } 20 | let averageGrade = TotalGrade / people; 21 | console.log(`${name} - ${averageGrade.toFixed(2)}.`); 22 | sumGrade += averageGrade; 23 | 24 | command = input[index]; 25 | index += 1; 26 | 27 | } 28 | let average = sumGrade / counter 29 | console.log(`Student's final assessment is ${average.toFixed(2)}.`); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programming-Basics-with-JavaScript---february-2022 2 | ## Uploading all tasks given in lab and exercise classes, also all task given as more exercise for homework. 3 | ## All task solves gives 100/100 at SoftUni judge system 4 | -------------------------------------------------------------------------------- /While Loop - Exercise/Cake.js: -------------------------------------------------------------------------------- 1 | function cake(input) { 2 | let index = 2; 3 | let width = input[0]; 4 | let lenght = input[1]; 5 | let command = input[2]; 6 | 7 | let sumPieces = 0; 8 | 9 | while (command !== "STOP") { 10 | command = Number(input[index]); 11 | sumPieces += command; 12 | if (sumPieces > width * lenght) { 13 | console.log( 14 | `No more cake left! You need ${sumPieces - width * lenght} pieces more.` 15 | ); 16 | break; 17 | } 18 | index += 1; 19 | command = input[index]; 20 | } 21 | 22 | if (command === "STOP") { 23 | console.log(`${width * lenght - sumPieces} pieces are left.`); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /While Loop - Exercise/Coins.js: -------------------------------------------------------------------------------- 1 | function coins(input) { 2 | let resto = Number(input[0]); 3 | 4 | let counter = 0; 5 | 6 | while (resto >= 2) { 7 | resto -= 2; 8 | resto = Number(resto.toFixed(2)); 9 | counter += 1; 10 | } 11 | 12 | while (resto >= 1) { 13 | resto -= 1; 14 | resto = Number(resto.toFixed(2)); 15 | counter += 1; 16 | } 17 | 18 | while (resto >= 0.5) { 19 | resto -= 0.5; 20 | resto = Number(resto.toFixed(2)); 21 | counter += 1; 22 | } 23 | 24 | while (resto >= 0.2) { 25 | resto -= 0.2; 26 | resto = Number(resto.toFixed(2)); 27 | counter += 1; 28 | } 29 | 30 | while (resto >= 0.1) { 31 | resto -= 0.1; 32 | resto = Number(resto.toFixed(2)); 33 | counter += 1; 34 | } 35 | 36 | while (resto >= 0.05) { 37 | resto -= 0.05; 38 | resto = Number(resto.toFixed(2)); 39 | counter += 1; 40 | } 41 | 42 | while (resto >= 0.02) { 43 | resto -= 0.02; 44 | resto = Number(resto.toFixed(2)); 45 | counter += 1; 46 | } 47 | 48 | while (resto >= 0.01) { 49 | resto -= 0.01; 50 | resto = Number(resto.toFixed(2)); 51 | counter += 1; 52 | } 53 | 54 | console.log(counter); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /While Loop - Exercise/Exam Preparation.js: -------------------------------------------------------------------------------- 1 | function examPreparation(input) { 2 | let index = 0; 3 | let numberOfBadGrade = Number(input[index]); 4 | index += 1; 5 | let problemName = input[index]; 6 | let grade = 0; 7 | 8 | let avarageGrade = 0; 9 | let counter = 0; 10 | 11 | while (problemName !== "Enough") { 12 | grade = Number(input[index + 1]); 13 | avarageGrade += grade; 14 | if (grade <= 4) { 15 | counter += 1; 16 | if (numberOfBadGrade === counter) { 17 | console.log(`You need a break, ${numberOfBadGrade} poor grades.`); 18 | break; 19 | } 20 | } 21 | index += 2; 22 | problemName = input[index]; 23 | } 24 | if (problemName == "Enough") { 25 | problemName = input[index - 2]; 26 | console.log( 27 | `Average score: ${(avarageGrade / ((index - 1) / 2)).toFixed(2)}` 28 | ); 29 | console.log(`Number of problems: ${(index - 1) / 2}`); 30 | console.log(`Last problem: ${problemName}`); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /While Loop - Exercise/Moving.js: -------------------------------------------------------------------------------- 1 | function moving(input) { 2 | let index = 3; 3 | let width = input[0]; 4 | let lenght = input[1]; 5 | let hight = input[2]; 6 | let command = input[3]; 7 | 8 | let sumOfBoxes = 0; 9 | 10 | while (command !== "Done") { 11 | command = Number(input[index]); 12 | sumOfBoxes += command; 13 | if (sumOfBoxes > width * lenght * hight) { 14 | console.log( 15 | `No more free space! You need ${sumOfBoxes - width * lenght * hight} Cubic meters more.` 16 | ); 17 | break; 18 | } 19 | index += 1; 20 | command = input[index]; 21 | } 22 | 23 | if (command === "Done") { 24 | console.log(`${width * lenght * hight - sumOfBoxes} Cubic meters left.`); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /While Loop - Exercise/Old Books.js: -------------------------------------------------------------------------------- 1 | function oldBooks(input) { 2 | let index = 0; 3 | let nameBook = input[index]; 4 | index += 1; 5 | 6 | let currentBook = 0; 7 | 8 | while (currentBook !== "No More Books") { 9 | currentBook = input[index]; 10 | if (currentBook == nameBook) { 11 | console.log(`You checked ${index - 1} books and found it.`); 12 | break; 13 | } 14 | index += 1; 15 | } 16 | if (currentBook == "No More Books") { 17 | console.log("The book you search is not here!"); 18 | console.log(`You checked ${index - 2} books.`); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /While Loop - Exercise/Vacation.js: -------------------------------------------------------------------------------- 1 | function vacation(input) { 2 | let index = 0; 3 | let moneyNeeded = Number(input[index]); 4 | index += 1; 5 | let money = Number(input[index]); 6 | index += 1; 7 | 8 | let action = String; 9 | 10 | let countSpendDay = 0; 11 | let totalDay = 0; 12 | 13 | let actionMoney = 0; 14 | 15 | while (countSpendDay !== 5) { 16 | action = input[index]; 17 | actionMoney = Number(input[index + 1]); 18 | totalDay += 1; 19 | if (action === "spend") { 20 | money -= actionMoney; 21 | if (money < 0) { 22 | money = 0; 23 | } 24 | countSpendDay += 1; 25 | } else { 26 | countSpendDay = 0; 27 | money += actionMoney; 28 | if (money >= moneyNeeded) { 29 | console.log(`You saved the money for ${totalDay} days.`); 30 | break; 31 | } 32 | } 33 | index += 2; 34 | } 35 | if (countSpendDay == 5) { 36 | console.log("You can't save the money."); 37 | console.log(`${totalDay}`); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /While Loop - Exercise/Walking.js: -------------------------------------------------------------------------------- 1 | function walking(input) { 2 | let index = 0; 3 | let command = input[index]; 4 | 5 | let sumSteps = 0; 6 | 7 | while (command !== "Going home") { 8 | command = Number(input[index]); 9 | sumSteps += command; 10 | if (sumSteps >= 10000) { 11 | console.log("Goal reached! Good job!"); 12 | console.log(`${sumSteps - 10000} steps over the goal!`); 13 | break; 14 | } 15 | index += 1; 16 | command = input[index]; 17 | } 18 | 19 | if (command === "Going home") { 20 | sumSteps += Number(input[index + 1]); 21 | if (sumSteps < 10000) { 22 | console.log(`${10000 - sumSteps} more steps to reach goal.`); 23 | } else { 24 | console.log("Goal reached! Good job!"); 25 | console.log(`${sumSteps - 10000} steps over the goal!`); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /While Loop - Lab/Account Balance.js: -------------------------------------------------------------------------------- 1 | function accountBalance(input) { 2 | let index = 0; 3 | let command = input[index]; 4 | index += 1; 5 | 6 | let total = 0; 7 | 8 | while (command !== "NoMoreMoney") { 9 | let sum = Number(command); 10 | if (sum < 0) { 11 | console.log("Invalid operation!"); 12 | break; 13 | } 14 | total += sum; 15 | console.log(`Increase: ${sum.toFixed(2)}`); 16 | 17 | command = input[index]; 18 | index += 1; 19 | } 20 | console.log(`Total: ${total.toFixed(2)}`); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /While Loop - Lab/Graduation.js: -------------------------------------------------------------------------------- 1 | function graduation(input) { 2 | let index = 0; 3 | let nameStudents = input[index]; 4 | index += 1; 5 | 6 | let averageGrade = 0; 7 | 8 | let grade = Number(input[index]); 9 | 10 | while (grade >= 4.0) { 11 | averageGrade += grade; 12 | index += 1; 13 | grade = Number(input[index]); 14 | } 15 | index += 1; 16 | grade = input[index]; 17 | if (grade < 4.0) { 18 | console.log(`${nameStudents} has been excluded at ${index - 1} grade`); 19 | } else { 20 | console.log( 21 | `${nameStudents} graduated. Average grade: ${( 22 | averageGrade / 23 | (index - 2) 24 | ).toFixed(2)}` 25 | ); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /While Loop - Lab/Max Number.js: -------------------------------------------------------------------------------- 1 | function maxNumbers(input) { 2 | let index = 0; 3 | let commad = input[index]; 4 | index += 1; 5 | 6 | let maxNum = Number.MIN_SAFE_INTEGER; 7 | 8 | while (commad !== "Stop") { 9 | let num = Number(commad); 10 | if (maxNum < num) { 11 | maxNum = num; 12 | } 13 | commad = input[index]; 14 | index += 1; 15 | } 16 | console.log(maxNum); 17 | } 18 | -------------------------------------------------------------------------------- /While Loop - Lab/Min Number.js: -------------------------------------------------------------------------------- 1 | function minNumbers(input) { 2 | let index = 0; 3 | let commad = input[index]; 4 | index += 1; 5 | 6 | let minNum = Number.MAX_SAFE_INTEGER; 7 | 8 | while (commad !== "Stop") { 9 | let num = Number(commad); 10 | if (minNum > num) { 11 | minNum = num; 12 | } 13 | commad = input[index]; 14 | index += 1; 15 | } 16 | console.log(minNum); 17 | } 18 | -------------------------------------------------------------------------------- /While Loop - Lab/Password.js: -------------------------------------------------------------------------------- 1 | function password(input) { 2 | let index = 0; 3 | let username = input[index]; 4 | index += 1; 5 | let password = input[index]; 6 | index += 1; 7 | 8 | let data = input[index]; 9 | index += 1; 10 | 11 | while (password !== data) { 12 | data = input[index]; 13 | index += 1; 14 | } 15 | console.log(`Welcome ${username}!`); 16 | } 17 | -------------------------------------------------------------------------------- /While Loop - Lab/Read Text.js: -------------------------------------------------------------------------------- 1 | function readText(input) { 2 | let index = 0; 3 | let command = input[index]; 4 | index += 1; 5 | while (command != "Stop") { 6 | let name = command; 7 | console.log(name); 8 | command = input[index]; 9 | index += 1; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /While Loop - Lab/Sequence 2k+1.js: -------------------------------------------------------------------------------- 1 | function sequences(input) { 2 | let number = Number(input[0]); 3 | 4 | let counter = 1; 5 | 6 | while (counter <= number) { 7 | console.log(counter); 8 | counter = counter * 2 + 1; 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /While Loop - Lab/Sum Numbers.js: -------------------------------------------------------------------------------- 1 | function sumNumbers(input) { 2 | let index = 0; 3 | let number = Number(input[index]); 4 | index += 1; 5 | 6 | let sum = 0; 7 | 8 | while (number > sum) { 9 | let num = Number(input[index]); 10 | index += 1 11 | sum += num 12 | } 13 | console.log(sum); 14 | } 15 | -------------------------------------------------------------------------------- /While-Loop - More Exercises/Average Number.js: -------------------------------------------------------------------------------- 1 | function averageNumber(input) { 2 | let n = Number(input[0]); 3 | 4 | let sum = 0; 5 | let average = 0; 6 | for (let i = 1; i < n + 1; i++) { 7 | let number = Number(input[i]); 8 | sum += number; 9 | } 10 | average = sum / n; 11 | console.log(average.toFixed(2)); 12 | } 13 | -------------------------------------------------------------------------------- /While-Loop - More Exercises/Dishwasher.js: -------------------------------------------------------------------------------- 1 | function dishwasher(input) { 2 | let index = 0; 3 | let command = input[index]; 4 | 5 | let countBottle = Number(input[index]); 6 | index++; 7 | 8 | let amountPreparation = 0; 9 | 10 | let leftoverDeterget = 0; 11 | let spentPreparationForDish = 0; 12 | let spentPreparationForPots = 0; 13 | 14 | let totalPots = 0 15 | let totalDish = 0; 16 | 17 | let detergentDish = 5; 18 | let detergentPots = 15; 19 | let detergent = 750; 20 | 21 | amountPreparation = countBottle * detergent; 22 | 23 | while (command !== "End") { 24 | 25 | if (amountPreparation < 0) { 26 | console.log(`Not enough detergent, ${Math.abs(amountPreparation)} ml. more necessary!`); 27 | break; 28 | } 29 | 30 | if (index % 3 === 0) { 31 | numberPots = Number(input[index]); 32 | spentPreparationForPots = numberPots * detergentPots; 33 | amountPreparation = (amountPreparation - spentPreparationForPots); 34 | totalPots += numberPots; 35 | leftoverDeterget = spentPreparationForPots; 36 | 37 | } else { 38 | numberDish = Number(input[index]); 39 | spentPreparationForDish = numberDish * detergentDish; 40 | amountPreparation = (amountPreparation - spentPreparationForDish); 41 | totalDish += numberDish; 42 | leftoverDeterget = spentPreparationForDish; 43 | 44 | } 45 | 46 | 47 | index++; 48 | command = input[index]; 49 | } 50 | 51 | if (amountPreparation >= 0) { 52 | console.log("Detergent was enough!"); 53 | console.log(`${totalDish} dishes and ${numberPots} pots were washed.`); 54 | console.log(`Leftover detergent ${amountPreparation} ml.`); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /While-Loop - More Exercises/Numbers Divided by 3 Without Reminder.js: -------------------------------------------------------------------------------- 1 | function numbersDivideByThreeWithoutReminder(){ 2 | for(let n = 1; n < 100; n ++){ 3 | if(n % 3 === 0){ 4 | console.log(n); 5 | } 6 | } 7 | } 8 | --------------------------------------------------------------------------------