Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Personality Test

deprecated_personality_quiz_script.livemd

Personality Test

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Return Home Report An Issue

Personality Test

In this exercise, you will create an Elixir script to run a personality test from the terminal.

Create a personality_test.exs script in the projects folder, which you should be able to run with:

$ elixir personality_test.exs

This will be a two choice personality test. You have creative freedom over what you would like the personality test to decide.

For our example, we’ll use a “Are you a dog person or a cat person?” test.

The personality test will ask the user 5 questions. Each question has 2 choices which help determine if they are one personality type or another.

For example,

  1. Do you love to go for walks? yes/no
  2. Do you value your alone time and need a lot of it? yes/no
  3. Are you generally high energy? yes/no
  4. Do you prefer sports or reading a book? sports/book
  5. Water or soda? water/soda

You can use IO.gets/1 to ask the user questions from the script.

Once finished with the quiz, it should print out a result based on their answers.

"You are a Dog person!"

Mark As Completed

file_name = Path.basename(Regex.replace(~r/#.+/, __ENV__.file, ""), ".livemd")

progress_path = __DIR__ <> "/../progress.json"
existing_progress = File.read!(progress_path) |> Jason.decode!()

default = Map.get(existing_progress, file_name, false)

form =
  Kino.Control.form(
    [
      completed: input = Kino.Input.checkbox("Mark As Completed", default: default)
    ],
    report_changes: true
  )

Task.async(fn ->
  for %{data: %{completed: completed}} <- Kino.Control.stream(form) do
    File.write!(progress_path, Jason.encode!(Map.put(existing_progress, file_name, completed)))
  end
end)

form

Commit Your Progress

Run the following in your command line from the curriculum folder to track and save your progress in a Git commit. Ensure that you do not already have undesired or unrelated changes by running git status or by checking the source control tab in Visual Studio Code.

$ git checkout solutions
$ git checkout -b personality-quiz-script-exercise
$ git add .
$ git commit -m "finish personality quiz script exercise"
$ git push origin personality-quiz-script-exercise

Create a pull request from your personality-quiz-script-exercise branch to your solutions branch. Please do not create a pull request to the DockYard Academy repository as this will spam our PR tracker.

DockYard Academy Students Only:

Notify your instructor by including @BrooklinJazz in your PR description to get feedback. You (or your instructor) may merge your PR into your solutions branch after review.

If you are interested in joining the next academy cohort, sign up here to receive more news when it is available.