Skip to content

Added trivia game script - #12

Open
DilyanaSt wants to merge 4 commits into
intro-to-git:mainfrom
DilyanaSt:feature/trivia-game
Open

DilyanaSt wants to merge 4 commits into
intro-to-git:mainfrom
DilyanaSt:feature/trivia-game

Conversation

@DilyanaSt

@DilyanaSt DilyanaSt commented Apr 7, 2026

Copy link
Copy Markdown

Closes #7

This PR adds a trivia game:

  • Uses arrays to store questions and answers
  • Handles multiple questions
  • Tracks score
  • Improved answer checking (case-insensitive and trims whitespace)

@DilyanaSt
DilyanaSt force-pushed the feature/trivia-game branch from f4c9c7a to 7c63bab Compare April 7, 2026 20:32

@Skfnrj Skfnrj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, the script is easy to follow and I like how you used arrays for the questions and answers. The case-insensitive check is also a nice touch.

Maybe you could also handle small variations in answers (like “the sky is blue”), but overall it looks good and works well.

@aminaballa24-dev

Copy link
Copy Markdown

This is nice, I like how you handled the answers with lowercase so it’s more flexible

@IvoPetrevski IvoPetrevski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for answering questions works without any problems. I think it would be better if you use an associative array. It would make it easier to track and add new questions and the array will be in a different order every time the script is executed. This would make the trivia game a bit more exciting.

Comment thread trivia-game.sh
@@ -0,0 +1,41 @@
#!/bin/bash

questions=(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works, but it might be more readable to use a associative array.

Comment thread trivia-game.sh

# convert both to lowercase + remove extra spaces
user_answer=$(echo "$answer" | xargs | tr '[:upper:]' '[:lower:]')
correct_answer=$(echo "${answers[$i]}" | tr '[:upper:]' '[:lower:]')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good data normalization on both sides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trivia game

5 participants