Coder Social home page Coder Social logo

wdi_1_ruby_assessment_basics's Introduction

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 o

At the end of the program the value of a and b are both 4. The variable a is initially set to 5 but later the value of a is set to the value of 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.

At the end of the program the variables have the following values: g = 12 e = 3 f = 9 f retains 9, as 'f == g' only tests if their values are the same and would return false, rather than assigning g's value to f (f = g) g is assigned the value of e + f which is 12, and even though the value of e does not change after it is initialized to 3 on the first line, it is re-assigned the value of 3 at the end, so it's value remains 3.

Question 3

weather = "cloudy"
weather == "cloudy"

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

The first line creates a variable called weather and assigns it the string "cloudy" the second line is a comparison asking if the variable weather is the same as the string "cloudy".

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 output would be "sushu is delicious" The variable x is initialized to 2, and then checked to see if it is equal to 3. It is not, so puts "sushi is tasty" does not execute. The elsif statement checks if x is greater than 0, which it is, and so puts "sushi is delicious" is executed.

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 output would be "I'm allergic!" The variable food is initialized to "walnut" and then the if statement checks to see if the variable food is the same as the strong "walnit", which it is. As a result puts "I'm allergic!" executes.

wdi_1_ruby_assessment_basics's People

Contributors

whtouche avatar tibbon avatar grantovich avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.