Exercise: Strings of colours

A String of favourite colours

Create a string containing the names and favourite colours of each person near you.

For example: "Our favourite colours are green and purple"

""
Reveal answer...
;; Just simply use a string
"We all love purple"

;; Using a function you can create a string and join values to create a string
(str "My favorite colours are" " " "green" " " "and" " ""purple")

Does the string contain your favorite colour

Use a function to see if a string contains a colour. See the Hint below if you are not sure how to start

For example, does the string "Rachel of York gave brown bread in vans" contain the colour brown?

()
Reveal answer...
(clojure.string/includes? "Rachel of York gave brown bread in vans" "brown")

The clojure.stringclojure.string library

Remember that there are specific functions you can use in the clojure.string library

results matching ""

    No results matching ""