Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var coins = 0;
- var tokens, result = '';
- input.forEach(function (elem) {
- tokens = elem.toLowerCase().split(' ');
- if (tokens[0] === 'coin') {
- if ((Number(tokens[1]) % 1 === 0) && (Number(tokens[1]) >= 0)) {
- coins += parseInt(tokens[1]);
- }
- }
- });
- result = 'gold : ' + parseInt(coins / 100) + '\n';
- coins %= 100;
- result += 'silver : ' + parseInt(coins / 10) + '\n';
- coins %= 10;
- result += 'bronze : ' + coins;
- console.log(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement