add javascripts basic

main
yikth 5 years ago
parent 84ae2d470f
commit d33562ea34

@ -0,0 +1,28 @@
var price = 1000;
/*
if (price > 100) { //true or false ---- Booloen
console.log ("You have 10% dicount for this item ");
console.log ("log again");
}
if (price === 100) { //note the operator!
console.log ("You have 8% discunt for this item");
}
if (price === 50) { //note the operator!
console.log ("Purchase for 100 or more to get discount")
}
*/
if (price > 100) {
console.log ("You have 10% dicount for this item ");
} else if (price === 100) {
console.log ("You have 8% discunt for this item");
} else if (price === 50) {
console.log ("Purchase for 100 or more to get discount");
} else {
console.log("invalid data");
}

@ -0,0 +1,21 @@
/*
for (var i=0; i<10; i=i+2) { //i - loop control variable
console.log(i);
}
*/
for (i=0; i<10; i++){
for(j=0; j<5; j++){
console.log(j);
}
}
/*
var i = 0;
while (i<10){
console.log(i);
i++;
}
*/

@ -0,0 +1,19 @@
//Some essential string object methods
var myStr = "I'm feeling great.";
var l = myStr.length;
console.log("charater count:" + l);
console.log(myStr[2]); //m
console.log(myStr[4]); //f
var subStr1 = myStr.slice(4,11); // returns starting position and up to (but not including) the ending position
var subStr2 = myStr.slice(12); //returns part of the string from position 10
console.log(subStr1);
console.log(subStr2);
var p1 = myStr.indexOf('feel');//returns 4, ie the substring is at pos 10
var p2 = myStr.indexOf('test');// returns -1, which means not found
console.log(p1 + ", " +p2)
console.log(myStr.replace('feel','game'))
console.log(myStr.toLowerCase());//convert entire string to lowercase
console.log(myStr.toUpperCase());//convert entire string to uppercase

@ -0,0 +1,24 @@
/* variables, numsbers, strings, mixed type operations,
template literals, Boolean, semicolon, LET/VAR, case-sensitive, comments */
var a = 10; //a is a name for memory location
let b = 20.5;
let givenName = "James"
var lastName = 'LIM'
var myText = "I'm feeling great.";
a = 20;
var c;
console.log(c); //undefined!
var d = null;
//console.log(D); //JS is case sensitive
console.log(d);
c = a+b;
d = a + lastName
const e= 10; //constant
//e = a+b;
let f = e < b;
let g = f + 1;
console.log(`Hello ${givenName}`); //
console.log("Hello " + givenName);
console.log(`value of a is ${a}, value of b is ${b}, value of c is ${c}, value of d is ${d}, value of e is ${e}`);
console.log(`value of f is ${f}, value of g is ${g}`);
console.log("I'm " + givenName + " " + lastName + ". " + myText);

@ -9,7 +9,8 @@ var d = 55;
// template literal `..`
console.log(`My answer is ${d}`);
var myStr = 'Hello World';
var myStr = "Hello \" World";
console.log(myStr);
var x = 10;
var y = 20;

Loading…
Cancel
Save