Advertisement
Guest User

6ta :)

a guest
Apr 4th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // I have a few ways to solve this taks.
  2.  
  3. function vowelsSumONE(params) {
  4.     let word = params.shift();
  5.  
  6.     let points = {
  7.         'a': 1, 'e': 2, 'i': 3, 'o': 4, 'u': 5
  8.     };
  9.  
  10.     let total = 0;
  11.  
  12.     for (let letter of word) {
  13.         if (points[letter]) {
  14.             total += points[letter]
  15.         }
  16.     }
  17.  
  18.     console.log(total);    
  19. }
  20.  
  21. // Secon option is from the presentation:
  22. function vowelsSumTWO(params) {
  23.     let word = params.shift();
  24.  
  25.     let total = 0
  26.  
  27.     for (let i = 0; i <= word.length; i++) {
  28.         switch (word[i]) {
  29.             case 'a': total += 1; break;
  30.             case 'e': total += 2; break;
  31.             case 'i': total += 3; break;
  32.             case 'o': total += 4; break;
  33.             case 'u': total += 5; break;
  34.         }
  35.     }
  36.  
  37.     console.log(total);    
  38. }
  39.  
  40. vowelsSumTWO(['bamboo']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement