svetlozar_kirkov

Daggers and Swords

Mar 21st, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     var validWeapons = [];
  3.     function Weapon(length, type, name) {
  4.         this.length = length;
  5.         this.type = type;
  6.         this.name = name;
  7.     }
  8.     for (var i in input) {
  9.         var temp = parseFloat(input[i]);
  10.         var tempLength = Math.floor(temp);
  11.         if (tempLength > 10) {
  12.             var tempWeapon = {};
  13.             tempWeapon.length = tempLength;
  14.             if (tempLength > 40) {
  15.                 tempWeapon.type = 'sword';
  16.             }
  17.             else {
  18.                 tempWeapon.type = 'dagger';
  19.             }
  20.             if ( tempLength % 10 === 1 || tempLength % 10 === 6 ) {
  21.                 tempWeapon.name = 'blade';
  22.             }
  23.             else if ( tempLength % 10 === 2 || tempLength % 10 === 7 ) {
  24.                 tempWeapon.name = 'quite a blade';
  25.             }
  26.             else if ( tempLength % 10 === 3 || tempLength % 10 === 8 ) {
  27.                 tempWeapon.name = 'pants-scraper';
  28.             }
  29.             else if ( tempLength % 10 === 4 || tempLength % 10 === 9 ) {
  30.                 tempWeapon.name = 'frog-butcher';
  31.             }
  32.             else if ( tempLength % 10 === 5 || tempLength % 10 === 0 ) {
  33.                 tempWeapon.name = '*rap-poker';
  34.             }
  35.             validWeapons.push(tempWeapon);
  36.         }
  37.     }
  38.     console.log('<table border="1">');
  39.     console.log('<thead>');
  40.     console.log('<tr><th colspan="3">Blades</th></tr>');
  41.     console.log('<tr><th>Length [cm]</th><th>Type</th><th>Application</th></tr>');
  42.     console.log('</thead>');
  43.     console.log('<tbody>');
  44.     for (var index in validWeapons) {
  45.         console.log('<tr><td>' + validWeapons[index].length + '</td>' +
  46.         '<td>' + validWeapons[index].type + '</td>' +
  47.         '<td>' + validWeapons[index].name + '</td></tr>');
  48.     }
  49.     console.log('</tbody>');
  50.     console.log('</table>');
  51. }
Advertisement
Add Comment
Please, Sign In to add comment