Simple Rock Paper Scissors game build using JuliaLang
Tags: julialang, beginners, opensource, learnings
Published: 2022-01-31 14:34:44

Hello everyone 👋, in this article📃 I'll be discussing about how I m learning JuliaLang by building mini projects.

Lets start building Rock Paper Scissors game using JuliaLang.
But first we definitely need an IDE or TextEditor for running JuliaLang code. 
We can use VSCode with required extension for running JuliaLang code but since I have just started with JuliaLang so I used [repl.it](https://replit.com/) here for coding and exploring JuliaLang(its an awesome online IDE try it).

> **Motivation behind getting started with Learning JuliaLang:**
1. Best part about JuliaLang is that it is easy to learn just like Python.
2. The execution speed of JuliaLang is similar to C/C++. That means it's fast.
3. And it is widely used for Data Science , Machine Learning , Deep Learning and even Web Development(And more lot stuff).
4. And JuliaLang Community is wide & inclusive,if you stuck somewhere while creating any project using JuliaLang. There are many amazing folks to help you. And if are mathematics, bioinformatics or something related to Statistics and Maths or even you are just a Tech Enthusiast join JuliaLang [slack channel](julialang.slack.com). You will find many awesome peers who are enthusiast from of the above fields.
5. Around 200+ JuliaLang packages are present to make your development work more easy.


Complete Code :

```Julia
# learning julialang basics by creating classical stone paper scissors game


function play_game()
    moves = ["rock","paper","scissor"]
    computer_move = moves[rand(1:3)]

    human_move = Base.prompt("Please enter stone, paper, or scissor")

    print("Rock...")
    sleep(1.0)

    print("Paper...")
    sleep(1.0)

    print("Scissors...")
    sleep(1.0)

    print("Shoot!\n")

    if computer_move == human_move
        print("You tied, please try again")
    elseif computer_move == "rock" && human_move == "scissor"
        print("You lose, the computer won with rock, please try again")
    elseif computer_move == "paper" && human_move == "rock"
        print("You lose, the computer won with paper, please try again")
    elseif computer_move == "scissor" && human_move == "paper"
        print("You lose, the computer won with scissor, please try again")
    else
        print("You won, the computer lost with $computer_move, nice work!")
    end

end

```

#### My Learnings from this mini project build:
1) Learned how to write comment in JuliaLang.
```Julia
# This is how we write JuliaLang comments
# hashtag followed with text you wanted to commented
```

2) Learned how to print text.
```Julia
print("Your text here inside double quotes")
```

3) Learned how to create function(without parameters)
```Julia
function fun_name()
.
your code here
.
end
```
Whenever you create function its necessary to tell compiler where to stop by using end keyword in JuliaLang.

4) Learned how to use conditional loop (if-elseif-else loop).
```Julia
function test(x, y)
           if x < y
               println("x is less than y")
           elseif x > y
               println("x is greater than y")
           else
               println("x is equal to y")
           end
       end
```
Whenever we use if-else or if-elseif-else conditional loop after the else condition statement we should use end keyword to tell compiler where does the conditional loops ends.

5) Learned about few inbuilt function.
   - sleep() : Its an inbuilt method of JuliaLang which comes under Base class and we don't need to import package for it. It basically stops execution of code for specified time. The minimum sleep time is 1 milliseconds.
```Julia
sleep(seconds)
```

   - rand() : It picks random element from array or list of elements. And similar to sleep method its an inbuilt method which comes under Base class.
```
rand(1:3)
```
Here we randomly selected 1 element from 3 elements inside the collection.



##### Source :
- [JuliaLang Docs](https://docs.julialang.org/en/v1/manual/getting-started/)

- Github Repository for mini Projects using JuliaLang
 (Thanks @logankilpatrick for providing awesome mini projects repository)
{%github logankilpatrick/Julia-Projects-for-Beginners no-readme%}