DEV Community

Cover image for Emojicode😎 (Variables)
LeafKn
LeafKn

Posted on

Emojicode😎 (Variables)

Part 2 of the Series on Emojicode.

Let's dive deep into coding with emojis.
In this part, I'll try to introduce you to what variables are and how are they implemented in Emojicode 💪.

Variable 🙄❓

A variable is simply a name that represents a particular piece of your computer’s memory that has been set aside for you to store, retrieve, and use data.
Variable store data types. We had a small introduction to strings in the last part - which is a data type!
Data types are just to tell computer what type of data it is.

Declaring and Assigning Variables:

Emojicode lets you declare two types of variables:

types

Declaring a constant variable:

🔤Earth🔤 ➡️ planet
💭🔜 planet is variable, ➡️ is assigning operator,  Earth is a string and is the value of planet variable 🔚💭

Enter fullscreen mode Exit fullscreen mode

Declaring a mutable variable:

6 ➡️ 🖍🆕 coins
💭🔜 coin is a variable, ➡️ is assigning operator,  6 is an integer and is the value of coin variable, 🖍🆕 means mutable 🔚💭

💭 Mutable variables *need* to be mutated or emojicode will smash an error on you.

Enter fullscreen mode Exit fullscreen mode

String Interpolation (printing your variable):

Just declaring variable is boring 🥱, we need to print them out.
To print variables, we need to wrap them around 🧲.

interpolation

Arithmetic Operations:

Emoji Operation Example
addition 2 ➕ 2 ➡️ number 💭 number is 4
subtraction 2 ➖ 2 ➡️ number 💭 number is 0
✖️ multiplication 2 ✖️ 2 ➡️ number 💭 number is 4
division 2 ➗ 2 ➡️ number 💭 number is 1
🚮 modulo 2 🚮 2 ➡️ number 💭 number is 0

Mutate the mutables 😎! Operator Assignments.

In Emojicode, operator assignment provides a short-hand method for modifying the value of variables.

Suppose we have a variable like this:

2 ➡️ 🖍🆕 mutate   💭 mutate is 0
Enter fullscreen mode Exit fullscreen mode
Emoji Operation Example
⬅️➕ addition assignment mutate ⬅️➕ 1 💭 mutate is now 3
⬅️➖ subtraction assignment mutate ⬅️➖ 1 💭 mutate is now 2
⬅️✖️ multiplication assignment mutate ⬅️✖️ 2 💭 mutate is 4
⬅️➗ division assignment mutate ⬅️➗ 2 💭 mutate is now 2
🚮 modulo assignment

Let's code a program 💻

gif

This is a very basic program. Pardon me if you are hecker 😁

program

See you in next part! Stay tuned :)

Top comments (1)

Collapse
 
ibnsamy96 profile image
Mahmoud Ibn Samy

Nice series. I'm wondering if I can build a real-world program using emojicode 😂