LoslegenKostenlos loslegen

Identify the body of a function

In Twenty-One, it is useful to have a function that determines the maximum of two competing players' hands. For example, imagine a scenario where playerA and playerB have the following hands:

  • playerA: queenDiamonds, threeClubs, aceHearts (worth 1), fiveSpades
  • playerB: kingHearts, jackHearts

Below is a simple version of that function, called maxHand, that ignores whether or not the hand busts. It also has an if/else expression, which you will learn how to write in an upcoming lesson.

def maxHand(handA: Int, handB: Int): Int = {
  if (handA > handB) handA
  else handB
}

In the previous video, the body of the function was emphasized as the only part of a function that you need to know for this course. What is the body of the maxHand function?

Diese Übung ist Teil des Kurses

Introduction to Scala

Kurs anzeigen

Interaktive Übung

Setze die Theorie in einer unserer interaktiven Übungen in die Praxis um

Übung starten