In Part 1, I tried using an if statement inside the method.
This time I'd like to use arguments to make the code a little cleaner!
This is the previous code.
sample.rb
def register
eraser = 110
pen = 150
bill = eraser + pen
if bill >= 200 #10 for purchases over 200 yen%off!!
bill * 0.9
end
end
puts register #Call the register method.
this
Let's define the numbers for eraser and pen
outside the method.
sample.rb
def register
eraser = 110 #Numerical value here
pen = 150 #Numerical value here
bill = eraser + pen
if bill >= 200
bill * 0.9
end
end
puts register
Add ()
after def register
and inside it
I'll put in eraser
and pen
.
sample.rb
def register(eraser, pen) #Comma between eraser and pen(,)And half-width space
# eraser =110 Delete here
# pen =150 Deleted here
bill = eraser + pen
if bill >= 200
bill * 0.9
end
end
puts register(150, 100) #Put a number here
puts register (150, 100)
These two numbers are
def register (eraser, pen)
Sent here.
Each eraser
is 150
pen
is 100
Will be sent.
sample.rb
def register(eraser, pen)
bill = eraser + pen
if bill >= 200
bill * 0.9
end
end
puts register(150, 100)
It's just a little cleaner! (Maybe)
It was today's output. : sweat:
Recommended Posts