Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. // Code your transform function here:
  2. function transform(obj){
  3. let key = '';
  4. let newObj= {};
  5. for(let item in obj){
  6. for(let letter in obj[item]){
  7. newObj[obj[item][letter].toLowerCase()] = Number(item);
  8. }
  9. }
  10. return newObj;
  11. }
  12.  
  13.  
  14. // Code your initialPrompt function here:
  15. const input = require('readline-sync');
  16.  
  17. let initialPrompt = input.question("Welcome to the Scrabble score calculator! \n \nWhich scoring algorithm would you like to use? \n \n0 - Scrabble: The traditional scoring algorithm. \n1 - Simple Score: Each letter is worth 1 point. \n2 - Bonus Vowels: Vowels are worth 3 pts, and consonants are 1 pt. \n \nEnter 0, 1, or 2:");
  18. while(initialPrompt > 2){
  19. initialPrompt = input.question("Please enter 0, 1, or 3");
  20. console.log(initialPrompt);
  21. }
  22.  
  23. // Code your runProgram function here:
  24.  
  25.  
  26. // Here is the oldScoreKey object:
  27. const oldScoreKey = {
  28. 1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'],
  29. 2: ['D', 'G'],
  30. 3: ['B', 'C', 'M', 'P'],
  31. 4: ['F', 'H', 'V', 'W', 'Y'],
  32. 5: ['K'],
  33. 8: ['J', 'X'],
  34. 10: ['Q', 'Z']
  35. };
  36.  
  37.  
  38.  
  39. // Use the transform function to create the newScoreKey object here:
  40. let newScoreKey = transform(oldScoreKey);
  41.  
  42. // Create your scoringAlgorithms array here:
  43. function simpleScore(word){
  44. let score = word.length;
  45. return score;
  46. }
  47.  
  48. function bonusVowels(word){
  49. let vowels = ['a','e', 'i', 'o', 'u'];
  50. let score = word.length;
  51. for(let i = 0; i < word.length; i++){
  52. if(vowels.includes(word[i].toLowerCase())){
  53. score += 2;
  54. }
  55. }
  56. return score;
  57. }
  58.  
  59. function scrabbleScore(obj,word){
  60. let score = 0
  61. for(let c of word){
  62. score += obj[c]
  63. console.log(score)
  64. console.log(c)
  65. }
  66. return score;
  67. };
  68. /*
  69. Takes object we created earlier with transform function
  70. and the word we went to score.
  71. */
  72. //function calculate_word(obj, word)
  73. //{
  74. // score = 0;
  75.  
  76. // Loop through each letter in the word because we have
  77. // an object that is holding letter values
  78. // for (c of word) {
  79. // Look inside our object and use
  80. // the current letter as the object key
  81. // and add the value to an on going total
  82. // score += obj[c];
  83. /// }
  84.  
  85. // Return final total!
  86. // / return score
  87.  
  88.  
  89. console.log(scrabbleScore('hello', newScoreKey));
  90. //console.log(bonusVowels("HELLO"));
  91. //console.log(simpleScore('hello'))
  92. // Call the runProgram function here:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement