Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let ageLily = Number(input[0]);
- let priceWashingMachine = Number(input[1]);
- let priceOneToy = Number(input[2]);
- let odd = 0;
- let even = 0;
- let toysPrice = 0;
- let moneyFinal = 0;
- let moneyPerBirth = 0;
- let allMoney = 0;
- let moneyLeft = 0;
- let countIncrease = 10;
- for (let i = 1; i <= ageLily; i++) {
- if (i % 2 !== 0) {
- odd += 1;
- } else {
- even += 1;
- }
- }
- for (let i = 1; i <= even; i++) {
- moneyPerBirth += countIncrease;
- countIncrease += 10;
- }
- moneyFinal = moneyPerBirth - even;
- toysPrice = odd * priceOneToy;
- allMoney = moneyFinal + toysPrice;
- moneyLeft = allMoney - priceWashingMachine;
- if (allMoney >= priceWashingMachine) {
- console.log(`Yes! ${moneyLeft.toFixed(2)}`);
- } else {
- moneyLeft = Math.abs(moneyLeft);
- console.log(`No! ${moneyLeft.toFixed(2)}`);
- }
- }
- solve([
- '10',
- '170',
- '6'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement