Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code your transform function here:
- function transform(obj){
- let key = '';
- let newObj= {};
- for(let item in obj){
- for(let letter in obj[item]){
- newObj[obj[item][letter].toLowerCase()] = Number(item);
- }
- }
- return newObj;
- }
- // Code your initialPrompt function here:
- const input = require('readline-sync');
- 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:");
- while(initialPrompt > 2){
- initialPrompt = input.question("Please enter 0, 1, or 3");
- console.log(initialPrompt);
- }
- // Code your runProgram function here:
- // Here is the oldScoreKey object:
- const oldScoreKey = {
- 1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'],
- 2: ['D', 'G'],
- 3: ['B', 'C', 'M', 'P'],
- 4: ['F', 'H', 'V', 'W', 'Y'],
- 5: ['K'],
- 8: ['J', 'X'],
- 10: ['Q', 'Z']
- };
- // Use the transform function to create the newScoreKey object here:
- let newScoreKey = transform(oldScoreKey);
- // Create your scoringAlgorithms array here:
- function simpleScore(word){
- let score = word.length;
- return score;
- }
- function bonusVowels(word){
- let vowels = ['a','e', 'i', 'o', 'u'];
- let score = word.length;
- for(let i = 0; i < word.length; i++){
- if(vowels.includes(word[i].toLowerCase())){
- score += 2;
- }
- }
- return score;
- }
- function scrabbleScore(obj,word){
- let score = 0
- for(let c of word){
- score += obj[c]
- console.log(score)
- console.log(c)
- }
- return score;
- };
- /*
- Takes object we created earlier with transform function
- and the word we went to score.
- */
- //function calculate_word(obj, word)
- //{
- // score = 0;
- // Loop through each letter in the word because we have
- // an object that is holding letter values
- // for (c of word) {
- // Look inside our object and use
- // the current letter as the object key
- // and add the value to an on going total
- // score += obj[c];
- /// }
- // Return final total!
- // / return score
- console.log(scrabbleScore('hello', newScoreKey));
- //console.log(bonusVowels("HELLO"));
- //console.log(simpleScore('hello'))
- // Call the runProgram function here:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement