Last active
June 19, 2022 10:50
-
-
Save nareshdevineni/5aa8fd77b58afa5c6b3458bf94e32163 to your computer and use it in GitHub Desktop.
Exercise for getting good with Javascript Variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //First name and last name are always a string | |
| let firstName = "Naresh"; | |
| let lastName = "Devineni"; | |
| //It is recommended to store age as a number because you might end up incrementing it automatically every year | |
| let age = 34; | |
| // Names are always strings | |
| let father = "D. Narsaiah"; | |
| let mother = "D. Laxmi"; | |
| //If "yes", "no" are the only possible answers, use Booleans | |
| let interestedInSports = true; | |
| let married = false; | |
| /* | |
| Now comes the complicated part with measurement related data. Different countries use different measurements for weight. | |
| For example, US people use pounds for weight while India, Newzealand Kilos for weight. | |
| I have instructed you to use kilos for weight and centimeters for height. | |
| So, are you going to store them as strings? | |
| or Will you store them as numbers by assuming that everybody will provide their weight in kilos and height in cm? | |
| The thing is there is no right answer for this. It changes from project to project based on the requirment at hand. | |
| So, for now, I am going with strings. But, later we will go with a proper solution. | |
| */ | |
| let height = 176cm; // This will throw a Javascript error because 176cm is not a valid number. | |
| let height = "176cm"; // This is the correct way! | |
| let weight = "72kgs"; | |
| /* Usually we use arrays or objects for storing multiple related values together inside a variable, but for the time being, let's go with a string */ | |
| let hobbies = "Playing Cricket, Performing SEO, Reading books"; | |
| // Addresses are full of text. So, they must be strings | |
| let address = "HIG 314, Flat. no: 400, Ameerpet, Hyderabad, India, 500072"; | |
| /******************************************* | |
| ****** Now let's update some variable ****** | |
| ********************************************/ | |
| // As you can see, you can get fancier with comments :P | |
| // Anyway, I grew older by one year :( | |
| age = 35; | |
| /* When you are updating variables, you can change the data type if you want to. For example, I changed the data type from Boolean to a String in the below example */ | |
| married = "It's complicated"; | |
| // I am now under weight :D | |
| weight = "70kg"; | |
| //End of the exercise 🥳. As you can see, you can also have emojis inside your code 🙈. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment