From the course: Introduction to Scala

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Solution: Greeting

Solution: Greeting - Scala Tutorial

From the course: Introduction to Scala

Solution: Greeting

(intro music) - Let's go through the solution for the chapter two challenge. So the first part of the challenge was to write a function called product which takes two parameters, both of type Int and returns an integer and multiplies these two parameters together. Let's try this out in our main method, so we want to printline the result of the product function. We'll call the product function with two numbers. Let's click play. Wonderful. And this outputs four because two times two is four of course. And the second part of the challenge was to write a function called greeting which takes a parameter called name of type string and has a default parameter, which I'm going to name stranger, the function outputs, a string. And I'm going to write hi name, so again we can printline this. We're going to call the greeting function so we can call it, let's say once with a name and then also once without a name. Let's…

Contents