You are viewing a single comment's thread. Return to all comments →
javaScript` solution
function processData(input) { const inputArr = input.split('\n'); const actual = inputArr[0].split(' ').map(Number); // Convert to numbers const expected = inputArr[1].split(' ').map(Number); // Convert to numbers const day = 0; const month = 1; const year = 2;
let fine = 0;
if (actual[year] > expected[year]) { fine = 10000; } else if (actual[year] === expected[year] && actual[month] > expected[month]) { fine = 500 * (actual[month] - expected[month]); } else if (actual[year] === expected[year] && actual[month] === expected[month] && actual[day] > expected[day]) { fine = 15 * (actual[day] - expected[day]); }
console.log(fine); } `
Seems like cookies are disabled on this browser, please enable them to open this website
Day 26: Nested Logic
You are viewing a single comment's thread. Return to all comments →
javaScript` solution
function processData(input) { const inputArr = input.split('\n'); const actual = inputArr[0].split(' ').map(Number); // Convert to numbers const expected = inputArr[1].split(' ').map(Number); // Convert to numbers const day = 0; const month = 1; const year = 2;
let fine = 0;
if (actual[year] > expected[year]) { fine = 10000; } else if (actual[year] === expected[year] && actual[month] > expected[month]) { fine = 500 * (actual[month] - expected[month]); } else if (actual[year] === expected[year] && actual[month] === expected[month] && actual[day] > expected[day]) { fine = 15 * (actual[day] - expected[day]); }
console.log(fine); } `