Goal: Your goal is to continue practicing TDD and Ruby syntax and to write tests before your code. You should no longer define methods in
main. Your logic should include custom classes with instance methods. All methods should be called on instances of a class.
Write a method that takes a word and returns the Scrabble score for that word. Here are the values of letters in Scrabble:
A, E, I, O, U, L, N, R, S, T 1 D, G 2 B, C, M, P 3 F, H, V, W, Y 4 K 5 J, X 8 Q, Z 10
Here is a spec to get you started:
it("returns a scrabble score for a letter") do expect("a".scrabble()).to(eq(1)) end
Write a method that translates numbers in numeric form into written words. For example, it would translate 384 into "three hundred eighty four". Use multiple hashes and the
.fetch() method to solve this.
Start small, and then get your code working for numbers up to 1 trillion.
If you've fully completed both projects listed above with time to spare, focus on the following:
Add additional code to your translator to take words and translate them into numbers.
Create a document parser that determines the total Scrabble score of all the words in the document. You should use built-in Ruby methods like
File.close() and then parse the document.
Create a document parser that compares two documents and checks which one has a higher Scrabble score. Or, if you’d like to practice building something more practical, build a parser that checks to see if two documents have the same content.
Lesson 10 of 22
Last updated more than 3 months ago.