Skip to content

Exercises 1 : JavaScript Basics 1 (16p)

Remember use JAMK/GitLab to return your exercises. Student need to test that exercise really work.

Exercise 01 - variables [2p]

Create HTML-file which include JavaScript. Define let v1 = "Hello" and let v2="World!" variables. Your application should create a new string based variable (name it result) which uses these two variables like this <h1>Hello World!</h1>. Add a new p element to your HTML and give some unique id for it. Use getElementById and .innerHTML to show your results varaible content in Web page. Use also console.log() to display your result value in Web browser's console.

Return: You should have one HTML file.

Exercise 02 - js.bin [2p]

Test above code in jsbin.com and some other playgournd. Save a screenshots.

Return: Screenshots about working code in jsbin.com and some other playground.

Exercise 03 - array [2p]

Define an array, which has a following values: ["JavaScript", "is", "excellent!"]. Create a sentence JavaScript is excellent! from your array data using a some loop in JavaScript. Display a created sentence in web console.

Return: HTML/JS files.

Exercise 04 - functions [2p]

Create a function which will take a three number based parameters. Function should display the biggest number. First create a three variables (you can define any numbers) and display those number values to web browser console. Call your function and display the biggest value.

Return: HTML/JS files.

Exercise 05 - functions [4p]

Create a function, which will take an array of integer values as parameter. Function should find numbers which are even and which are odd numbers. Function should dipslay first the original array and then array only with odd numbers. You can use console.log() to display values.

Return: HTML/JS files.

Exercise 06 - loops [4p]

Create HTML and JavaScript file where you define following variables

1
2
3
4
5
let array = [11, 22, 33, 44];
let sum = 0;
let count = 0;
let average;
let lines = '';

Calculate count and sum values with for of loop. Create lines variable contents with for loop.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// define variables

// use for of loop to calculate sum and count

// use for loop to create "lines" strings. One line is like "array[0] = 11" etc...
// line[0] = array[0] = 11
// line[1] = array[1] = 22

// show all lines

// show count, sum and average

Your application should display:

1
2
3
4
5
6
7
8
array[0] = 11
array[1] = 22
array[2] = 33
array[3] = 44

count: 4
sum: 110
average: 27.5

Note

You can use .toFixed() to round your display values.