What do I have to know about JavaScript?
What do I have to know about JavaScript?
JavaScript is a Script language programming and it works in our web browsers, some sites uses a lot of JavaScript code, JavaScript helps sites to interact with their users, here in this post we will see some basis things we have to know about JavaScript.
Variable declarations are so important to JavaScript because lets you to play with the data we got, we can declare a variable like this
var Name = "Franklin Alexis Lemus" /*We are giving to the variable Name a value at the same time we create it*/
Math Operations
Math Operations are so important in programming, and in JavaScript its easy to use them, here are some examples of Math Operations such as multiply, divide, sum, and substraction
var number = 1 + 1 /*Heres a variable that takes the sum of two numbers*/
var number = 1 - 1 /*Here is a variable that takes the substraction of two numbers*/
var number = 1 * 1 /*Heres a variable that takes the value of two numbers multiplied */
var number = 1 / 1 /*Heres a variable that takes the value of a number divided by another one*/
Alerts and WindowsMaybe sometimes we have seen a litle window with a message and buttons in our web browser, sometimes when we save changes, register, or delete something, these are some example of those windows or alerts
prompt("Type Your Name")/*This tool gives you the chance to type in a little Textbox in this case asking for a name*/
confirm("Ready?");/*This window gives you a message with two buttoms OK/Cancel*/
alert("Este es un mensaje");/*This window just give you a simple message and a buttom Ok or Accept"*/
if / else Functions
If/else functions are importants in programming, with If/else functions we can say to our program that if something happens, do "this" and if something else happens do this, for example I will ask for a Name and if the Name is Franklin Lemus I will show a message "Welcome Administrador" + My Name, but if its another name I will show a message "Welcome user" + The name typed
var Nombre = prompt("Dijite su nombre");
if(Nombre == "Franklin Lemus"){
alert("Bienvenido Administrador:" + Nombre)
}
else{
alert("Bienvenido user" + Nombre)
}
Switch & case
This function is similar to if /else but in this case we are asking for a number between 1 and 3 and if the number isnt between 1 and 3 we have a default message, so I cant use another number
var Numero = "Tree";
switch (Numero) {
case "One":
console.log("Your variable value is 1");
break;
case "two":
console.log("Your variable value is 2"); break;
case "three":
console.log("Your variable value is 3"); break;
default: console.log("Your variable value isnt between 1 y 3")}
Comentarios
Publicar un comentario