Skip to content

learn-co-students/mutability-quiz-seattle-web-060319

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Quiz: Understanding Mutability

Objectives

  1. Strengthen your understanding of method scopes.
  2. Strengthen your understanding of mutability in Ruby.

???

Mutability Challenge

?: We have the following method that takes in an argument of an array and a string:

def quiz_method(array, object)
  array << object
end

If we call the method in the following manner:

array = ["hi", "there"]

quiz_method(array, "quizmaster")

What is the variable array now equal to?

( )["hi", "there"] (X)["hi", "there", "quizmaster"]

?: If we execute the same method in the following manner:

array = [1, 2, 3]
quiz_method(array, 4)

What is the array variable now equal to?

(X)[1, 2, 3, 4] ( )[1, 2, 3]

?: If we perform the following:

string = "hi there "
string << "quizmaster!"

What is the value of string?

( )"hi there" (X)"hi there quizmaster!"

?: What is the return value of the following method call?

array = [1, 2, 3, 4]
array.each do |num|
  num * 2
end

(X)[1, 2, 3, 4] ( )[2, 4, 6, 8]

?: Below we have a method that accepts two arguments of two numbers:

def change_the_number(num1, num2)
  num1 = num1 + num2
end

If we call it in the following way:

number_one = 5
number_two = 3
change_the_number(number_one, number_two)

What is the value of number_one?

(X)5 ( )8

???

View Quiz: Understanding Mutability on Learn.co and start learning to code for free.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published