The goal of this project is to get more practice with writing Ruby programs. You will execute the code simply by visiting a particular URL in your browser. Your visit will trigger the execution of the Ruby code, and the output will appear in your browser window.
Ultimately, you will build this application:
http://omnicalc-target.herokuapp.com/
It is a collection of calculators that do various things; count the number of words in a block of text, the monthly payment for a loan, etc. Over time, we may add more and more calculators if we feel like it (if you have a suggestion for a calculator you think we should add, please let us know).
-
Ensure that this repo is a fork on your own account.
-
Setup a Cloud9 workspace as usual.
-
In a Terminal, run
bin/setup
. -
Run Project and visit your app in Chrome.
-
If all went well, you should see the New Word Count form. If not, let us know right away.
-
Type in some text and submit the form.
-
On the results page, you will currently see just a bunch of placeholders.
-
In Atom, find the
/app/controllers/calculations_controller.rb
file. -
Locate the part of the file that looks like this:
def word_count @text = params[:user_text] @special_word = params[:user_word] # ================================================================================ # Your code goes below. # The text the user input is in the string @text. # The special word the user input is in the string @special_word. # ================================================================================ @character_count_with_spaces = "Replace this string with your answer." @character_count_without_spaces = "Replace this string with your answer." @word_count = "Replace this string with your answer." @occurrences = "Replace this string with your answer." end
-
The code between the
def word_count
andend
is the program that gets executed. I have already written some code that retrieves the inputs from the form and places them into variables for you to use,@text
and@special_word
. -
Your job is to write code below the comments and, ultimately, store the correct values in the variables I created at the bottom of the method. For example, to solve the first part, call
.length
on the user's input,@text
, and assign the result to@character_count_with_spaces
.@character_count_with_spaces = @text.length
-
You have to figure out how to calculate the correct value for the rest:
@character_count_without_spaces
,@word_count
, and@occurrences
. Don't change the names of these variables; if you do, your results won't appear in the browser in the end. -
Refresh the results page in your browser to re-run your code and see new output.
-
You can write as much or as little code as it takes to produce the correct answer; create intermediate variables if you want, or do anything else that you learned about from class. It's all just the same Ruby as before.
-
Use the Continuous Integration workflow to save and submit your work after you complete each little task.
-
Next, work on the Loan Payment calculator. You'll again be working in the same file,
/app/controllers/calculations_controller.rb
. This time, scroll down to the methoddef loan_payment
and write your code in there as indicated by the comments. -
Some tasks are easier, some are much harder. For example, in the Descriptive Statistics calculator, finding the mode (the number that occurs most frequently in a list of numbers) is surprisingly hard. Do your best, but don't get discouraged if you can't quite solve it.
-
For the mode calculation, just worry about the simplest case; when there's one number that occurs most frequently, that should be shown as the mode. I won't be testing the case that there's a tie.
-
Make lots of commits and Push them to GitHub as you are working.
-
I suggest making a new branch for every new feature that you start working on.
-
Ask lots of questions!