567643e7016656be29e9b30e06c4ad61
javascript1
lab1
v2
rasb14
2018-11-14 16:39:42
v3.1.3 (2018-09-13)

Generated 2018-11-14 17:39:42 by dbwebb lab-utility v3.1.3 (2018-09-13).


Lab 1 - variables and builtins

The foundation of variables, numbers, strings and basic arithmetic and built in functions.

Use MDN as your reference and base to solving the exercises.

1. Variables, numbers and built-in functions

Use variables, numbers and built-in functions.

One way to round a float to a certain amount of decimals is:

Math.round(val*10000)/10000

Where val is your float number.

Exercise 1.1 (1 points)

Create two variables, floatOne and floatTwo.

Give them the values 719.08 and 805.16.

Create a variable called result and assign to it the sum of the variables above.

Answer with the result, rounded to two decimals.

Exercise 1.2 (1 points)

Create a variable someIntText and give it a string value of "277.521 crocodile".

Use the function parseInt() to find out the integer representation of the text.

Assign the value to your result-variable.

Answer with the result.

Exercise 1.3 (1 points)

Use your variable someIntText.

Use the function parseFloat() to find out the float representation of the text.

Assign the value to your result-variable.

Answer with the result.

Exercise 1.4 (1 points)

Use the method max(), in Math, to find out the highest number in the serie:

401,339,956,831

Assign the number to your result-variable.

Answer with the result.

Exercise 1.5 (1 points)

Use the Math property PI to get the float value of ‘Pi’. Round the result to 4 decimals.

Assign the number to your result-variable.

Answer with the result.

2. Strings and built-in functions

Work with strings and find out about the built-in functions.

Exercise 2.1 (1 points)

Create a variable called wordOne and assign the word “mouse” to it.

Add (concatenate) the number 440 to the word and answer with the resulting variable.

Exercise 2.2 (1 points)

Use the built-in method charAt() on the word “bulldog” to return the character at a given index.

Answer with the character at index 0.

Exercise 2.3 (1 points)

Use the built-in method toUpperCase() to transform the string:

"I am in a glass case of emotion." to uppercase.

Answer with the result.

Exercise 2.4 (1 points)

Use the built-int property length to find out the length of the string: "bulldog".

Answer with the result.

Exercise 2.5 (1 points)

Use the built-int method substr() to extract the last three characters of the word: "bulldog".

Answer with the result.

3. Extra assignments

Solve these optional questions to earn extra points.

Exercise 3.1 (3 points)

Create a Date object called myDate and initiate it with: "Aug 23, 1992".

Use the built-in function Date.getFullYear() to get the year from your Date object.

Answer with the result.

Exercise 3.2 (3 points)

Create a new Date object that is equal to myDate plus 16 days.

Use Date.getDate() and answer with the day of the month.


567643e7016656be29e9b30e06c4ad61