Skip to content

Instantly share code, notes, and snippets.

@maliabadi
Created October 19, 2012 01:44
Show Gist options
  • Save maliabadi/3915809 to your computer and use it in GitHub Desktop.
Save maliabadi/3915809 to your computer and use it in GitHub Desktop.
Week One
# WEEK ONE ASSIGNMENT TEMPLATE
beatles = ["John", "Paul", "George", "Ringo"]
names = "FRANK, Thomas"
foo = 3
bar = 1
an_array_of_numbers = [3,2,1,2]
sandwich_hash = {'frank' => 14, 'thomas' => 19.0}
# START ASSIGNMENT CODE
## Set the variable "answer_number_one" as the sum of the variables "foo" and "bar"
## Set the variable "answer_number_two" as the sum of all of the numbers in "an_array_of_numbers"
## Set the variable "answer_number_three" as the sum of all the lengths of all of the names of the beatles
## Set the variable "answer_number_four" to be the second element in the array "an_array_of_numbers"
## Set the variable "answer_number_five" to be the sum of the second and third numbers in "an_array_of_numbers"
## Set the variable answer_array_one as to be an Array of the names listed in the string "names" (converted to lower case)
## Set the variable "answer_string_one" to say "Hello" to the first name in answer_array_one (with the name in proper case)
## Set the variable "answer_string_two" to say "Hello" to the second name in answer_array_one (all upper case, with a period between each letter)
## Set the variable "answer_string_three" to state how many sandwiches Frank has, using the variable 'sandwich_hash'
## The word 'frank' should not appear in this answer. Reference elements in answer_array_one.
## Set the variable "answer_string_four" to state how many sandwiches Thomas has,using the variable 'sandwich_hash'
## The word 'thomas' should not appear in this answer. Reference elements in answer_array_one.
## Set the variable "answer_array_two" to be an Array of strings, where each element says "Hello, " to every element in the "beatles" array
## Set the variable "answer_array_three" to be an Array of strings, where each element says "Hello, " to every element in the "beatles" array ending in a consonant, and says "Hi, " to every element in the "beatles" array ending in a vowel.
## Set the variable "answer_hash_one" to be a Hash where every name in the "beatles" array is mapped to how many characters it took to address them in "answer_array_three"
# END ASSIGNMENT CODE
# If your program runs correctly, the word "PASS" will appear when you run this file. Otherwise "FAIL" will appear.
if answer_number_one == 4
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 4"
puts "\t GOT: #{answer_number_one}"
end
if answer_number_two == 8
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 8"
puts "\t GOT: #{answer_number_two}"
end
if answer_number_three == 19
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 19"
puts "\t GOT: #{answer_number_three}"
end
if answer_number_four == 2
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 2"
puts "\t GOT: #{answer_number_four}"
end
if answer_number_five == 3
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 3"
puts "\t GOT: #{answer_number_five}"
end
if answer_string_one == "Hello, Frank"
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 'Hello, Frank'"
puts "\t GOT: #{answer_string_one}"
end
if answer_string_two == "Hello, T.H.O.M.A.S"
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 'Hello, T.H.O.M.A.S'"
puts "\t GOT: #{answer_string_two}"
end
if answer_string_three == "Frank has 14 sandwiches"
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 'Frank has 14 sandwiches'"
puts "\t GOT: #{answer_string_three}"
end
if answer_string_four == "Thomas has 19 sandwiches"
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: 'Thomas has 19 sandwiches'"
puts "\t GOT: #{answer_string_four}"
end
if answer_array_one == ["frank", "thomas"]
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: #{["frank", "thomas"]}"
puts "\t GOT: #{answer_array_one ? answer_array_one : nil}"
end
if answer_array_two == ["Hello, John", "Hello, Paul", "Hello, George", "Hello, Ringo"]
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: #{["Hello, John", "Hello, Paul", "Hello, George", "Hello, Ringo"]}"
puts "\t GOT: #{answer_array_two ? answer_array_two : nil}"
end
if answer_array_three == ["Hello, John", "Hello, Paul", "Hi, George", "Hi, Ringo"]
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: #{["Hello, John", "Hello, Paul", "Hi, George", "Hi, Ringo"]}"
puts "\t GOT: #{answer_array_three ? answer_array_three : nil}"
end
if answer_hash_one.is_a?(Hash) and answer_hash_one["John"] == 11 and answer_hash_one["Paul"] ==11 and answer_hash_one["George"] == 10 and answer_hash_one["Ringo"] == 9
puts "PASS"
else
puts "FAIL"
puts "\t EXPECTED: #{{"John"=>11, "Paul"=>11, "George"=>10, "Ringo"=>9}}"
puts "\t GOT: #{answer_hash_one ? answer_hash_one : nil}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment