Skip to content

Commit 31e7a93

Browse files
committed
wrote tranlate function
1 parent 6f1ceb9 commit 31e7a93

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

scrabble-scorer.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function initialPrompt() {
3737
return info;
3838
};
3939

40-
let newPointStructure;
40+
let newPointStructure = {}; //TODO: make this an object of 26 letter keys and the values consistent with the points from the oldPointStructure
4141

4242
let simpleScorer = function (word) {
4343
word = word.toUpperCase();
@@ -94,18 +94,38 @@ function scorerPrompt() {
9494
}
9595
return scoringAlgorithms[scorerProgramIndex].scorerFunction;
9696
};
97-
// create an array with the scorer functions, from the user input, call the relavant algorithym and print the word and score
9897

99-
function transform() { };
98+
function transform(oldPointStructureObject) {
99+
let newPointStructureObject = {};
100+
// loop through object
101+
102+
for (let item in oldPointStructureObject) {
103+
// data variables need for new object
104+
let currentObject = oldPointStructureObject[item];
105+
let newKey = currentObject.type.toLowerCase();
106+
let newValue = currentObject.item.toLowerCase();
107+
108+
// add these to new object key:value pair
109+
newPointStructureObject[newKey] = newValue;
110+
111+
}
112+
return newPointStructureObject;
113+
};
114+
console.log("Letters with score '4':", oldPointStructure[4]);
115+
console.log("3rd letter within the key '4' array:", oldPointStructure[4][2]);
116+
117+
let letters = oldPointStructure[8];
118+
console.log("Letters with score '8':", letters);
119+
console.log("2nd letter within the key '8' array:", letters[1]);
100120

101121
function runProgram() {
102122
let wordInput = initialPrompt();
103123
let scorerFunction = scorerPrompt();
104124
let score = scorerFunction(wordInput);
105-
console.log(`Score for'${wordInput}': ${score}`);
125+
// let transformOldToNew = transform(oldPointStructure);
126+
console.log(`Score for '${wordInput}': ${score}`);
127+
106128
}
107-
// console.log("algorithym name: ", scoringAlgorithms[2].name);
108-
// console.log("scorerFunction result: ", scoringAlgorithms[2].scorerFunction('JavaScript'));
109129

110130
// Don't write any code below this line //
111131
// And don't change these or your program will not run as expected //

0 commit comments

Comments
 (0)