EXERCISE: Converting numbers to positions

Convert numbers to positions

In English we say someone came 1st, rather than someone came 1.

Write a function called position with an argument called number

if the number equals 1, then the function should return "1st" If number is not 1, then return an error message, such as: "Sorry, the number is not supported"

(defn position [number]
  (if ;; condition
      ;; then
      ;; else
(position 1)


str can be used to join things together into a string

Positions such as 2nd & 3rd will be incorrect, but this can be fixed in a following exercise.

The linguistic name for this is called ordinal numbers)

Reveal answer...
(defn position [number]
  (if (= 1 number)
    (str number "s")1st"
    (str "Sorry, the number " number " is not supported"))

(position 1)

results matching ""

    No results matching ""