Dexter Jin

Experiments07 Uploaded

1 +function addPrice(amount) {
2 + this.price = amount;
3 +}
4 +function book(title, author) {
5 + this.title = title;
6 + this.author = author;
7 + this.addPrice = addPrice;
8 +}
9 +
10 +var bookList = new Array(new book("Perl1", "Mohtashim"),new book("Smith", "Mohtashim"),new book("Carl", "Mohtashim"),new book("Perl2", "Mohtashim"));
11 +
12 +console.log(bookList);
13 +console.log("After Sorting");
14 +//bookList.sort(sortBook);
15 +console.log(bookList);
1 +function slice(str, start, end) {
2 +
3 +}
4 +var str = "Apples are round, and apples are juicy.";
5 +var sliced = str.slice(1, 3);
6 +console.log( sliced );
7 +console.log( slice(str, 1, 3));
1 +function reverse (input) {
2 +
3 +}
4 +var arr = [0, 1, 2, 3];
5 +console.log ("Reversed array is : " + arr.reverse() );
6 +console.log ("Reversed array is : " + reverse(arr));
1 +
2 +var alpha = ["a", "b", "c"];
3 +var numeric = [1, 2, 3];
4 +var alphaNumeric = alpha.concat(numeric);
5 +console.log("alphaNumeric : " + alphaNumeric );
6 +
7 +
8 +var numbers = [1, 4, 9];
9 +var element = numbers.pop();
10 +console.log("element is : " + element );
11 +
12 +var numbers = new Array(1, 4, 9);
13 +var length = numbers.push(10);
14 +console.log("new numbers is : " + numbers );
15 +
16 +var arr = [0, 1, 2, 3].reverse();
17 +console.log("Reversed array is : " + arr );
18 +
19 +console.log("Reversed Again : " + arr.reverse());
20 +
21 +
22 +var element = [105, 1, 2, 3].shift();
23 +console.log ("Removed element is : " + element );
24 +
25 +
26 +var arr = new Array("orange", "mango", "banana", "sugar");
27 +var length = arr.unshift("water");
28 +console.log("Returned array is : " + arr );
29 +console.log("Length of the array is : " + length );
30 +
1 +var test = new Array(1,2,3,4,5,6);
2 +
3 +for (var aa in test) {
4 + console.log(aa); // Set breakpoint here
5 +}
1 +function concatenate(first, last)
2 +{
3 + var full;
4 + full = first + last;
5 + return full;
6 +}
7 +function secondFunction()
8 +{
9 + var result;
10 + result = concatenate('Zara', 'Ali');
11 + console.log (result );
12 +}
13 +secondFunction();
1 +var val = new Number(100.000);
2 +
3 +console.log(val.toExponential());
4 +console.log(val.toFixed());
5 +console.log(val.toLocaleString());
6 +console.log(val.toPrecision());
7 +console.log(val.toString());
1 +function addPrice(amount) {
2 + this.price = amount;
3 +}
4 +function book(title, author) {
5 + this.title = title;
6 + this.author = author;
7 + this.addPrice = addPrice;
8 +}
9 +var myBook = new book("Perl", "Mohtashim");
10 +myBook.addPrice(100);
11 +console.log("Book title is : " + myBook.title);
12 +console.log("Book author is : " + myBook.author);
13 +console.log("Book price is : " + myBook.price);
1 +var val = new String("test");
2 +
3 +console.log(val.charAt(1));
4 +console.log(val.charCodeAt(1));
5 +console.log(val.concat("aaa"));
6 +console.log(val.indexOf("st"));
7 +console.log(val.indexOf("t"));
8 +console.log(val.lastIndexOf("t"));
9 +console.log(val.replace("te","a"));
10 +console.log(val.slice(2));
11 +console.log(val.split("es"));
12 +console.log(val.substr(2,2));