File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -11,3 +11,6 @@ A collection of simple bash scripts.
11
11
## Functions
12
12
1 . [ What day is today?] ( scripts/what-day-today.sh ) : It prints which day of the week is today
13
13
2 . [ Square a number] ( scripts/squarenumber.sh ) : A simple function that squares an integer
14
+
15
+ ## $RANDOM
16
+ 1 . [ Guess number] ( scripts/guess-number-game.sh ) : User should guess a number from 1 to 100
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Lucas Saito, 2020/04/08
3
+ # Simple game to guess a number from 1 to 100
4
+ # The person has 5 tries to guess the number
5
+
6
+
7
+ RANDOM_NUMBER=$(( $RANDOM % 100 + 1 ))
8
+ TRIES=5
9
+ GUESS=0
10
+
11
+ echo " Welcome to the guessing game!"
12
+ echo " Guess a number from 1 to 100:"
13
+
14
+ while [[ GUESS -lt TRIES ]]; do
15
+ read guess_number
16
+ if [[ guess_number -eq RANDOM_NUMBER ]]; then
17
+ echo " You've won! The number was $RANDOM_NUMBER "
18
+ exit 0
19
+ else
20
+ TRIES=$(( TRIES - 1 ))
21
+ echo " You miss! You have ${TRIES} tries left!"
22
+ fi
23
+ done
24
+ echo " You lost!"
25
+ exit 0
You can’t perform that action at this time.
0 commit comments