Could someone explain these Ruby assigment operators to me?


#1

Hey guys,completely new to programming here and looking to become proficient in javascript,html,css,and jquery(mostly front-end stuff) and before i managed to get into Java i was told to go and learn Ruby first! Now i was doing good untill this part,which is also my first stagnation point which i just cant solve right now!

This is the problem: http://prntscr.com/jz7mxp

I cant for the life of me understand how do i get this result from the previous task: http://prntscr.com/jz7njw

Im having trouble understanding how += , -= , *= , and /= work ! If someone could point me in the right direction i would be grateful

Edit: OK i figured it out 2 minutes after making this post and i dont know how to delete im sorry guys,the answer was so easy += is A=A+B im so sorry guys!


#2

Those are assignment operators that evaluate the left side, taking into account the operation and the value on the right side to assign a new value to the variable.

a = 10
a *= 5
puts a    # 50

This is essentially,

a = a * 50

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.