Ruby Assessment - Day 2

Fork this repository, and clone the fork to your local computer. Edit this README.md file to contain the answers, and then make a pull request on Github to turn in the assessment.

Question 1

a = 5
b = 4
a = b

At the end of this program, what are the values of a and b? Try to explain, in plain English, how you got your answer for each one.

a = 4, b = 4. at the end of the code the value of a is reset to the value fo b, which is 4

Question 2

e = 3
f = 9
g = e + f
f == g
e = 3

At the end of this program, what are the values of e, f, and g? Try to explain, in plain English, how you got your answer for each one.

e = 3, f = 12, g = 12. at the end of the code g = e(3) + f(9) then f is set equal to g and e is reset to 3

Question 3

weather = "cloudy"
weather == "cloudy"

What is the difference between these two statements? Explain your answer.

the first statement is setting a value to weather the second value is comparing the variable to the string (false)

Question 4

x = 2

if x == 3
  puts "sushi is tasty"
elsif x > 0
  puts "sushi is delicious"
end

Imagine that you take the code from this question, save it to a file called sushi.rb, and run ruby sushi.rb in your Terminal.

What would be the output? Explain your answer.

the code would return "sushi is delicious" because its x != 3 but is greater than 0

Question 5

food = "walnut"

if food == "walnut"
  puts "I'm allergic!"
end

Imagine that you take the code from this question, save it to a file called snack.rb, and run ruby snack.rb in your Terminal.

What would be the output? Explain your answer.

the code would return "I'm allergic!" because the value of food variable is equal to "walnut"