JavaScript in Plain Language (2015)
PART I: AT THE GATES OF ENLIGHTENMENT
1.6 Lab work 2
Please fire up your JavaScript Console again
( CTRL SHIFT j or CMD SHIFT j or ALT-CMD-j ).
Declaring variables, assigning values, using basic properties and methods
( See the results on the next page )
1- Declare a variable named x and give it a string value of
"The quick brown fox jumps over the lazy dog".
2- Display x;
3- Find out the length of the data in variable x.
4- Display x in uppercase. Hint: toUpperCase()
5- Now convert the original x to uppercase, instead of just displaying it.
6- Call x again.
7- Finally convert the variable x to lowercase again. Hint: toLowerCase()
8- Call x just to be sure.
9- BONUS:
Declare variable y and assign it the value of x, but in uppercase.
10- Call y.
11- EXTRA, EXTRA BONUS:
Declare a variable named z and assign to it the numeric value of the length of x.
12- Call z.
(See the results on the next page. At this time, do the same exercises as you verify the answers on the next page. Practice, practice, practice)
Results:
1- Declare a variable named x and give it a string value of
"The quick brown fox jumps over the lazy dog":
var x = "The quick brown fox jumps over the lazy dog";
2- Display x:
x;
It displays "The quick brown fox jumps over the lazy dog"
3- Find out the length of the data in variable x:
x.length;
It displays 43, as of 43 characters including spaces.
4- Display x in uppercase:
x.toUpperCase();
It displays "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
5- Now convert the original x to uppercase, instead of just displaying it:
x = x.toUpperCase();
6- call x again:
x;
It displays "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
7- Finally convert the variable x to lowercase again:
x = x.toLowerCase();
8- Call x just to be sure:
x;
It displays "the quick brown fox jumps over the lazy dog"
9- BONUS:
Declare variable y and assign it the value of x, but in uppercase.
var y = x.toUpperCase();
10- Call y:
y;
It displays "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
11- EXTRA, EXTRA BONUS:
Declare a variable named z and assign to it the numeric value of the length of x:
var z = x.length;
12- Call z:
z;
It displays 43, the value of z is 43.
END OF LAB