2. The difference between Javascript and Ruby (Githud, 2008)
Ruby:
def create
@milestone = Milestone.new @params['milestone']
@milestone.creator = @person
@milestone.domain = @person.domain
if milestone.save
flash['notice'] = 'Milestone ' + @milestone.name + ' is created.'
redirect_to_action 'show', :id => @milestone.id
else
render_action 'new'
end
Javascript:
this.create = function(req, res) {
with (res) {
res.milestone = Milestone.newInstance(req['milestone']);
milestone.creator_id = person.id;
milestone.domain_id = person.domain_id;
if (milestone.save()) {
flash['notice'] = 'Milestone ' + milestone.name + ' is created.';
redirectToAction('show', milestone.id);
} else
renderAction('newInstance');
}
}
-Ruby use elsif and else whereas , javascript use elseif and else
- Javascript use open bracket for conditions () and {} whereas Ruby didn't use that
Challenge Problem
1. Compare the three dogs name in alphabetical order
Result
2. FizzBuzz Source
FizzBuzz Result
3. Compare the program code between Ruby and Python - dog years calculator
- Python is using the function method to work on the coding, and this function can call by the program itself
- Syntax is not the same between Ruby and Python, in fact, they peform the same task, for instances,
a. put for Ruby and print for Python
b. Elsif for Ruby and elif for Python
c. bracket for conditions under Python and not for Ruby
References:
Githud, 2008, 'New and Edit Miliestone'
No comments:
Post a Comment