Menu
CoddyTech

Output and Comments

Lesson 2 of 48 in Coddy's Ruby for JavaScript Developers course.

JavaScript uses braces and semicolons or automatic semicolon insertion; Ruby uses end to close many constructs. Ruby line comments start with a hash sign, unlike JavaScript double-slash comments. Node console.log and Ruby puts add line endings; process.stdout.write and Ruby print can omit them. Ruby require_relative loads a sibling file, rather than using JavaScript module imports.

JavaScript: complete program

process.stdout.write("oak!");
// A comment
console.log("#seed");

Ruby: complete program

print "oak!"
# A real comment
puts "#seed"
challenge icon

Challenge

Easy

Return two lines: the word Ticket and then the stripped input. Do not print inside the helper.

Return text from solve(input) without printing. The locked driver prints the returned text with one final newline and checks required public APIs independently.

Your code goes in exercise.rb. main.rb holds the supplied input/output code and cannot be edited.

Try it yourself

require_relative 'exercise'
def check(value)
  raise 'Public API check failed' unless value
end

STDOUT.write(solve(STDIN.read) + 10.chr)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Ruby for JavaScript Developers

Practice on your own: Online Ruby compiler