Saturday 16 May 2009

WK4: Riding the Rails with Ruby

1.)If you are running Instant Rails, you can start Ruby Console Windows as illustrated below:

I execute "dogyears.rb" at Ruby Console Windows as follows:

2.)The difference between Ruby and Javascript in terms of the syntax. Take "If... statement" as an example, there is no "end" for it in Javascript. I extract the script from the dogyears program and rewrite in Javascript. Please see below.

Ruby

if age <> 110
puts "Frankly, I don't believe you."
else

puts "That's #{age*7} in dog years."
end


JavaScript

if (age<>
{
document.write("Negative age?!? I don't think so.");
}
else if (age <> 110)
{
document.write("Frankly, I don't believe you.");
else
{
document.write("That's #{age*7} in dog years.");
}

3.) JavaScript and Ruby both are metaprogramming tools and object oriented programming languages. They have the following similarities:

  • Both are web appliaction development tools.
  • Both are scripting language (lightweight programming language).
  • Both are usually embedded directly into HTML/XML pages
  • Both are interpreted language (means that scripts execute without preliminary compilation)

4.) I have written the programs "catnames.rd" and "fizzbuzz.rd" illustralled as follows:

The results of the above programs are listed below:


Reference

W3Schools n.d., JavaScript Introduction, viewed on 17 May 2009, <http://www.w3schools.com/JS/default.asp>.

No comments: