Dexter Jin

Chapter 07 Updated

var a = 33;
var b = 10;
var c = "Test";
console.log("a + b = ");
result = a + b;
console.log(result);
console.log("a - b = ");
result = a - b;
console.log(result);
console.log("a / b = ");
result = a / b;
console.log(result);
console.log("a % b = ");
result = a % b;
console.log(result);
console.log("a + b + c = ");
result = a + b + c;
console.log(result);
a = a++;
console.log("a++ = ");
result = a++;
console.log(result);
b = b--;
console.log("b-- = ");
result = b--;
console.log(result);
var a = 33;
var b = 10;
console.log("Value of a => (a = b) => ");
result = (a = b);
console.log(result);
console.log("Value of a => (a += b) => ");
result = (a += b);
console.log(result);
console.log("Value of a => (a -= b) => ");
result = (a -= b);
console.log(result);
console.log("Value of a => (a *= b) => ");
result = (a *= b);
console.log(result);
console.log("Value of a => (a /= b) => ");
result = (a /= b);
console.log(result);
console.log("Value of a => (a %= b) => ");
result = (a %= b);
console.log(result);
var a = 2; // Bit presentation 10
var b = 3; // Bit presentation 11
console.log("(a & b) => ");
result = (a & b);
console.log(result);
console.log("(a | b) => ");
result = (a | b);
console.log(result);
console.log("(a ^ b) => ");
result = (a ^ b);
console.log(result);
console.log("(~b) => ");
result = (~b);
console.log(result);
console.log("(a << b) => ");
result = (a << b);
console.log(result);
console.log("(a >> b) => ");
result = (a >> b);
console.log(result);
var a = 10;
var b = 20;
console.log("(a == b) => ");
result = (a == b);
console.log(result);
console.log("(a < b) => ");
result = (a < b);
console.log(result);
console.log("(a > b) => ");
result = (a > b);
console.log(result);
console.log("(a != b) => ");
result = (a != b);
console.log(result);
console.log("(a >= b) => ");
result = (a >= b);
console.log(result);
console.log("(a <= b) => ");
result = (a <= b);
console.log(result);
var a = 10;
var b = 20;
var linebreak = "<br />";
console.log ("((a > b) ? 100 : 200) => ");
result = (a > b) ? 100 : 200;
console.log(result);
console.log ("((a < b) ? 100 : 200) => ");
result = (a < b) ? 100 : 200;
console.log(result);
var numbers = new Array(1,2,2,3,4)
for (var num in numbers) {
// key and Value
console.log(num + " = " + numbers[num]);;
}
console.log ("Exiting from the loop!");
var age = 20;
if( age > 18 ) {
console.log("Qualifies for driving");
}
var age = 15;
if( age > 18 ) {
console.log("Qualifies for driving");
} else {
console.log("Does not qualify for driving");
}
var book = "maths";
if( book == "history" ) {
console.log("History Book");
} else if( book == "maths" ) {
console.log("Maths Book");
} else if( book == "economics" ) {
console.log("Economics Book");
} else {
console.log("Unknown Book");
}
var a = true;
var b = false;
console.log("(a && b) => ");
result = (a && b);
console.log(result);
console.log("(a || b) => ");
result = (a || b);
console.log(result);
console.log("!(a && b) => ");
result = (!(a && b));
console.log(result);
var grade='A';
console.log("Entering switch block");
switch (grade)
{
case 'A':
console.log("Good job");
break;
case 'B':
console.log("Pretty good");
break;
case 'C':
console.log("Passed");
break;
case 'D':
console.log("Not so good");
break;
case 'F': console.log("Failed");
break;
default:
console.log("Unknown grade")
}
console.log("Exiting switch block");
switch (grade)
{
case 'A':
console.log("Good job");
case 'B':
console.log("Pretty good");
case 'C':
console.log("Passed");
case 'D':
console.log("Not so good");
case 'F':
console.log("Failed");
default:
console.log("Unknown grade");
}
console.log("Exiting switch block");
var a = 10;
var b = "String";
result = (typeof b == "string" ? "B is String" : "B is Numeric");
console.log("Result => ");
console.log(result);
result = (typeof a == "string" ? "A is String" : "A is Numeric");
console.log("Result => ");
console.log(result);
var name = "Ali";
var money;
money = 2000;
console.log("my name is " + name);
console.log("my money is " + money);
var myVar = "global"; // Declare a global variable
function checkscope( ) {
var myVar = "local";
// Declare a local variable
console.log("print myVar " + myVar);
}
console.log("print myVar " + myVar);
checkscope();
var count = 0;
console.log("Starting Loop ");
while (count < 10) {
console.log("Current Count : " + count);
count++;
}
console.log("Loop stopped!");
var count = 0;
console.log("Starting Loop");
do {
console.log("Current Count : " + count);
count++;
} while (count < 5);
console.log ("Loop stopped!");
function addPrice(amount) {
this.price = amount;
}
function book(title, author) {
this.title = title;
this.author = author;
this.addPrice = addPrice;
}
var bookList = new Array(new book("Perl1", "Mohtashim"),new book("Smith", "Mohtashim"),new book("Carl", "Mohtashim"),new book("Perl2", "Mohtashim"));
console.log(bookList);
console.log("After Sorting");
//bookList.sort(sortBook);
console.log(bookList);
function slice(str, start, end) {
}
var str = "Apples are round, and apples are juicy.";
var sliced = str.slice(1, 3);
console.log( sliced );
console.log( slice(str, 1, 3));
function reverse (input) {
}
var arr = [0, 1, 2, 3];
console.log ("Reversed array is : " + arr.reverse() );
console.log ("Reversed array is : " + reverse(arr));
var test = new Array(1,2,3,4,5,6);
for (var aa in test) {
console.log(aa);
}
No preview for this file type
No preview for this file type