My journey through web designing
I wanted to create my own website and app . So I started with the first step. I decided to learn the web designing for creating website. I got to know about one of the good course from where I can start with beginning of programming to creating my own site. Its called neog.camp where I started learning with joy and practically doing the things. I started my journey of learning those programming languages which are required for web designing. Few points I wanted to share with you which may help you in learning web designing and creating CLI app.
How I created my first CLI app?
Repl.it
First thing I got introduced to is repl.it. This is one of the coolest platform to code. We need to create our account first then we are good to go. It is a platform where we can code in different type of languages like Java, Nodejs, Javascript ,C++, Ruby etc. We need to create new repl by selecting language & giving specific name to it. Then we can write the code & after clicking on run we get the output of our code. As there are so many options given for languages, you can select in which language you want to code. I started with NodeJS.
Let’s see few points from NodeJS :
The first program which we do most of the time is “Hello world”. So I started with the first Hello World program.
- Just one command which will print whatever we write inside console.log. It is like cout() in cpp/printf in java .
code: console.log(“Hello World”);
2. readlineSync is a keyword which we use in nodejs for taking user input. Sometime we have to first import some library so that we can use them in code. Like that here also we insert/install with command lines. We define this readlineSync as below:
code:
var readlineSync = require(“readline-Sync”);
var name = readlineSync.question(“Your ask to user”);
OR you can just browse as readlineSync you can get the code along with information for this. You can use this link.
3. In programs you will define variables wherever required. Variables are just like placeholders inside the computer which can be used to place anything which you want with respect to datatypes(There are different types of datatypes like String, Number, Boolean browse to know more about it ). Use variables with such names which will make others easy to understand your code.
4. Here you can concatenate the strings by using ‘+’ sign.
code:
var Name= “Deepa”;
var msg=”Welcome” + Name;
console.log(msg);
5. What is programming?
In simple words we can say as : Input →Processing →Output
Programming is nothing but we take some input for example some numbers & do processing on it by writing some function or some action like add/sub etc on those numbers, then print output from it.
6. As like other programming languages NodeJS also consist of conditional statements, loops.
- if(cond1==true)
{
console.log()
} - if(cond1==true)
{
console.log()
}
else
{
console.log()
} - nested if else
- while(cond==true)
{
console.log()
} - do{
console.log()
} while(cond==true)
7. Function is a repeating piece of processing while input and output changes. Function parameters are the names given in function definition. Function arguments are the values given to those parameters while calling the the function.
Code:
function add(num1,num2)
{
sum=num1+num2;
return sum;
}
function(2,3);
Here in above code add is the function name ,num1&num2 are the parameters and 2,3 are the arguments given to function while calling add function.
Bonus point:
() →call a function
{} →when we write block of code
[] →array define
8. Array is a collection of values. These values are placed in ordered form. Each values are called as elements specified by an index. Array can hold different types of values like string, number, boolean etc.
Code:
var arr1 =[“one”, “two”, “three”]
console.log(arr1[0]);
output →one
array index starts with 0 and goes on increasing till the array length.
9. Objects in programming are just like our real life objects. Any objects like ball, doll, table etc. consist of it’s own properties like its shape, color, weight, height, value etc. We use their properties while mentioning them somewhere. Same like this objects in programming language works. We define objects with some name which consist of its properties divided as key : values. So whenever we want to use that particular property of that specific object in our code we can just directly access its values with keys. It’s little bit complex thing but in short you can keep the meaning of objects as I said above. Browse to explore more in it.
In below example superman is object name. Blue,High,100 are the values of keys color, power, strength. These are called properties of objects which can be accessed by using dot(.). To access color of the superman object we write superman.color. There are many inbuilt properties like for array we use arrayname.length(). Here length is a function which is a property of array object.
Code:
var superman={
color: “Blue”,
power: “High”,
strength: “100”
}
console.log(superman.color);
output —>Blue
10. Read & Write file are also one of the important concept when you are using some files in your code. Reading from file is something like you have some data written in one file and you want to read that data or some data from that file in your code then use readfile function. If you want to write some data or want to store some data from your code to the file then use writefile function. You can get full syntax of these and many more things like appendfile,handling error etc. on internet.
Bonus point:Use chalk in your code to make it more colorful and interesting for creating CLI apps.
CLI app creation
After learning all these things I coded small parts by using all these concepts then combined all together to make one app. Firstly I took one subject or topic for the app. I decide to create an app like game which anyone would like to play. So I made collection of few questions along with it’s answer. Placed these questions & answer as key and value type in objects. Then taken username & stored in variable so that I can use them at last for result declaration. Then taken array to store all those different objects of questions. To access each question one by one I used for loop. For checking user given answer is correct or not I used function. For counting the scores & comparing them with different users I used one temp file from where I read score of previous user from file & compare them from function then write to the output along with high score. I have used those score counts to mention the current user score and previous user and if he defeated high score then congratulated him. To make it more attractive used chalk concept in my code. Now you can just share repl.it link of that repl to your friends to check who can get high scores. In this way you can also create your own app and play around the things. Do not forget to share with your friends or relatives. Sharing your efforts or work can make you feel happy .Even if it is small share it with others it can motivate you to do more.