Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function evaluate(array)
- {
- var value = 0;
- var strValue = "";
- var currentLine = [];
- var counterGold =0;
- var counterSilver =0;
- var counterBronze =0;
- for(var i in array)
- {
- currentLine = array[i].split(" ");
- strValue = currentLine[0].toLowerCase().trim();
- value = Number(currentLine[1]);
- if(strValue == "coin")
- {
- if(typeof value == 'number')
- {
- if(value % 1 === 0)
- {
- //GOLD
- if(value == 100)
- {
- counterGold += 1;
- }
- if(value > 100)
- {
- counterGold += value / 100;
- }
- //SILVER
- if(value == 10)
- {
- counterSilver += 1;
- }
- if(value > 10 && value < 100)
- {
- counterSilver += value / 10;
- }
- //BRONZE
- if(value == 1)
- {
- counterBronze += 1;
- }
- if(value > 1 && value < 10)
- {
- counterBronze += value;
- }
- }
- }
- }
- }
- /*console.log("gold : " + typeof intcounterGold);
- console.log("silver : " + typeof counterSilver);
- console.log("bronze : " + typeof counterBronze);*/
- console.log("gold : " + intcounterGold);
- console.log("silver : " + counterSilver);
- console.log("bronze : " + counterBronze);
- }
- var input = ['coin 1 ','coin two','coin 5','coin 10.50','coin 20','coin 50','coin hundred','cigars 1'];
- evaluate(input);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement