Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Week1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="js1-w2.js"></script>
</body>
</html>
175 changes: 175 additions & 0 deletions Week1/js1-w1-A.A.A.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Greetings

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split your homework up in different files? As requested in the assignment:

For all the following exercises create a new .js file. Try to find a proper name for each file or make a small comment about what it does inside for future reference.


console.log ('Hello World!'); //English

console.log ('Halo, Dunia!'); // Indonesian

console.log ('Ciao Mondo!'); // Italian

console.log ('Hola Mundo!'); // Spanish


// Debug single quote issue

console.log('I\'m awesome');

// Variables & Values

var x;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use var please, use let or const


console.log("the value of my variable x will be: a number");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the value of x will be a number, are you sure this is correct?


console.log(x);

x = 12;

console.log("the value of my variable x will be: a number");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the value of x will be a number, are you sure this is correct?


console.log(x);

var y = 'Tom';

console.log("the value of my atring y will be: a name");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same:) as above


console.log(y);

var y = y + '&Jerry';

console.log("the value of my string y will be: a cartoon name");

console.log(y);

var z = 7.25;

console.log(z);

// Round z to the closest integer

var round = Math.round;

var a = round(z);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you can also do this in one line, like this:

const a = Math.round(z);


console.log(a);

// Print higher value z or a

if (a<z) {
var i = z;
console.log(i);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also do this directly:

if (a<z) {
    console.log(z);
} else {
    console.log(a);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or with Math.max


} else {
var i = a;
console.log(i);

}

// Animals Names

var myFavoriteAnimals;

console.log('The value of heros is: animales\'s names');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct, heros is not the name of the variable and the value is incorrect


console.log(myFavoriteAnimals);

myFavoriteAnimals = ['monkey', 'horse', 'turtle'];

console.log(myFavoriteAnimals);

myFavoriteAnimals = myFavoriteAnimals + [', baby pig'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cleaner (and better) solution is:

myFavoriteAnimals.push('baby pig');

I think this works better:)


console.log(myFavoriteAnimals);

// String Length

let myString = "this is a test";

console.log(myString);

console.log(myString.length);

// Types of Data

var success = 'Congats! the data type of your variables is identical!';

console.log(success + ' * this is a string');

console.log(typeof success);


var failure = 'Oops! the data type of your variables is different!';

console.log(failure + ' * this is a string');

console.log(typeof failure);


var number = 1;

console.log(number + ' * this is a number');

console.log(typeof number);


var boolean = true;

console.log(boolean + ' * this is a boolean');

console.log(typeof boolean);


var array = [0, 1, 2, 3, 4];

console.log(array + ' * this is an object');

console.log(typeof array);

// Testing type of data

if (typeof success === typeof failure) {

console.log(success);

} else {
console.log(failure);
}


if (typeof success === typeof number) {
console.log(success);

} else {
console.log(failure);
}


if (typeof boolean === typeof array) {
console.log(success);

} else {
console.log(failure);
}

// Explaining %

console.log(x);

console.log ('x % 5 will be 2 which is the leftover number that cannot be divided on 5');

console.log(x % 5);

// Array with multiple data types

console.log('following array contains 2 numbers, 2 strings and a boolean');

var multipleTypesArray = [0, 'hero', 2, 'too', false];

console.log(multipleTypesArray);

// Comparing infinities

if (10/0 === 6/0) {
console.log('Yes! they\'re equal!');

} else {
console.log('There\'s no equality in this!');
}