Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cleverLily(input) {
- let age = Number(input[0]);
- let machine = Number(input[1]);
- let toyPrice = Number(input[2]);
- let sum = 0;
- let toy = 0;
- let birthday = 10;
- for (let i = 3; i < age + 3; i++) {
- if (i % 2 === 0) {
- sum += birthday - 1;
- birthday += 10;
- } else {
- toy++;
- }
- }
- sum += toy * toyPrice;
- if (sum >= machine) {
- console.log(`Yes! ${(sum - machine).toFixed(2)}`);
- } else {
- console.log(`No! ${(machine - sum).toFixed(2)}`);
- }
- }
- Решение с тернарен оператор леко тарикатската:
- function cleverLily(input) {
- let age = Number(input[0]);
- let machine = Number(input[1]);
- let toyPrice = Number(input[2]);
- for (let i = 1; i <= age; i++) {
- machine -= i % 2 == 0 ? 5 * i - 1 : toyPrice
- }
- console.log(`${machine > 0 ? "No" : "Yes"}! ${Math.abs(machine).toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement