-
Notifications
You must be signed in to change notification settings - Fork 256
Abdullah Al Ahmad #114
Abdullah Al Ahmad #114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Explaining % | ||
|
||
x = 12; | ||
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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Animals Names | ||
|
||
let myFavoriteAnimals; | ||
|
||
console.log('The value of myFavoriteAnimals is: undefined then an object \'array\' '); | ||
|
||
console.log(myFavoriteAnimals); | ||
|
||
myFavoriteAnimals = ['monkey', 'horse', 'turtle']; | ||
|
||
console.log(myFavoriteAnimals); | ||
|
||
myFavoriteAnimals = myFavoriteAnimals + [', baby pig']; | ||
|
||
console.log(myFavoriteAnimals); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Types of Data | ||
|
||
let success = 'Congats! the data type of your variables is identical!'; | ||
|
||
console.log(success + ' * this is a string'); | ||
|
||
console.log(typeof success); | ||
|
||
|
||
let failure = 'Oops! the data type of your variables is different!'; | ||
|
||
console.log(failure + ' * this is a string'); | ||
|
||
console.log(typeof failure); | ||
|
||
|
||
let number = 1; | ||
|
||
console.log(number + ' * this is a number'); | ||
|
||
console.log(typeof number); | ||
|
||
|
||
let boolean = true; | ||
|
||
console.log(boolean + ' * this is a boolean'); | ||
|
||
console.log(typeof boolean); | ||
|
||
|
||
let 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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Greetings | ||
|
||
console.log ('Hello World!'); //English | ||
|
||
console.log ('Halo, Dunia!'); // Indonesian | ||
|
||
console.log ('Ciao Mondo!'); // Italian | ||
|
||
console.log ('Hola Mundo!'); // Spanish | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Debug single quote issue | ||
|
||
console.log('I\'m awesome'); | ||
|
||
// variables & Values | ||
|
||
let x; | ||
|
||
console.log("the value of my variable x will be: undefined "); | ||
|
||
console.log(x); | ||
|
||
x = 12; | ||
|
||
console.log("the value of my variable x will be: a number 12 "); | ||
|
||
console.log(x); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!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>JS-week2</title> | ||
</head> | ||
<body style ="text-align: center; padding: 10vw;"> | ||
<h1 style="color: red; font: 3em sans-serif;">JS-week2</h1> | ||
<script src="helloWorld.js"></script> | ||
<script src="imAwesome.js"></script> | ||
<script src="tom&jerry.js"></script> | ||
<script src="roundNumber.js"></script> | ||
<script src="arrays.js"></script> | ||
<script src="moreStrings.js"></script> | ||
<script src="dataType.js"></script> | ||
<script src="%.js"></script> | ||
<script src="multiDataTypes.js"></script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// String Length | ||
|
||
let myString = "this is a test"; | ||
|
||
console.log(myString); | ||
|
||
console.log(myString.length); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Array with multiple data types | ||
|
||
console.log('following array contains 2 numbers, 2 strings and a boolean'); | ||
|
||
let 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!'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
let z = 7.25; | ||
|
||
console.log(z); | ||
|
||
// Round z to the closest integer | ||
|
||
let round = Math.round; | ||
|
||
let a = round(z); | ||
|
||
console.log(a); | ||
|
||
// Print higher value z or a | ||
|
||
if (a<z) { | ||
let i = z; | ||
console.log(i); | ||
|
||
} else { | ||
let i = a; | ||
console.log(i); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let y = 'Tom'; | ||
|
||
console.log("the value of my string y will be: a string"); | ||
|
||
console.log(y); | ||
|
||
y = y + '&Jerry'; | ||
|
||
console.log("the value of my string y will be: a string"); | ||
|
||
console.log(y); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Use the list of vehicles to write an advertisement. So that it prints something like: "Amazing Joe's Garage, we service cars, motorbikes, caravans and bikes.". (Hint: use a for loop.) | ||
|
||
// Hint, the output should be correct English with all the punctuation in place (that's the challenge). So plurals for the vehicle types, commas followed by a single space, the word and to replace the final comma and closed off by a period. | ||
|
||
|
||
let ad = "Amazing Joe's Garage, we service "; | ||
function advertisement (){ | ||
for( i = 0 ; i < vehicles.length; i++){ | ||
|
||
if (i == vehicles.length-1){ | ||
ad += 's' + ' and ' + vehicles[i] + 's' + '.'; | ||
}else if(i == vehicles.length-2){ | ||
ad += vehicles[i]; | ||
} | ||
else { ad += vehicles[i]+ 's' + ', ' ; | ||
} | ||
}console.log(ad) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, it would be more readable if you add more spaces and align your brackets ( And I would advise to put the code of
|
||
|
||
// adding one vehicles to the list | ||
|
||
vehicles.push('scooter'); | ||
|
||
advertisement(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
let favoriteAnimals = ["blowfish", "capricorn", "giraffe"]; | ||
|
||
favoriteAnimals.push('turtle'); | ||
|
||
console.log(favoriteAnimals); | ||
|
||
favoriteAnimals.splice(1,0,'meerkat'); | ||
|
||
console.log('the value of the array will be 5 strings') | ||
|
||
console.log(favoriteAnimals); | ||
|
||
console.log('The array has a length of: ', favoriteAnimals.length) | ||
|
||
favoriteAnimals.splice(3,1); | ||
|
||
console.log(favoriteAnimals); | ||
|
||
console.log('The item you are looking for is at index: ', favoriteAnimals.indexOf('meerkat')); | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Create a function named colorCar that receives a color, and prints out, 'a red car' for example. | ||
|
||
function colorCar(color){ | ||
console.log('a ' + color + ' car'); | ||
} | ||
|
||
colorCar('red'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!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>JS-week3</title> | ||
</head> | ||
<body | ||
style ="text-align: center; padding: 10vw;"> | ||
|
||
<h1 style="color: red; font: 3em sans-serif;">JS-week3</h1> | ||
|
||
<script src="strings.js"></script>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you forgot some parts of the homework? I think assignment 12 untill 16 are missing, see the homework |
||
<script src="arrays.js"></script> | ||
<script src="sumFun.js"></script> | ||
<script src="colorFun.js"></script> | ||
<script src="vehicleType.js"></script> | ||
<script src="vehicle.js"></script> | ||
<script src="vehicleList.js"></script> | ||
<script src="advertisement.js"></script> | ||
|
||
|
||
<!-- | ||
|
||
<script src="roundNumber.js"></script> | ||
<script src="arrays.js"></script> | ||
<script src="moreStrings.js"></script> | ||
<script src="dataType.js"></script> | ||
<script src="%.js"></script> | ||
<script src="multiDataTypes.js"></script> --> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let myString = "hello,this,is,a,difficult,to,read,sentence"; | ||
|
||
console.log(myString.length); | ||
|
||
console.log(myString.replace(/,/g," ")); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Create a function that takes 3 arguments and returns the sum of the these arguments. | ||
|
||
function sum(){ | ||
let sum =0; | ||
for(let i=0;i<arguments.length;i++){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically this is correct, but I think that the assignment meant that you explicitly define three arguments and combine those. but I guess you know how to do that, since you've done it in a more complex way. So it's okay There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A tip: This is a pretty clever solution actually. But more difficult in use for other programmers if you collaborate on the code, because it is not intuitive for someone to know how many arguments they have to pass to the function and what will happen to them. So this is just a tip for the future, this solution is clever but not really good if you are collaborating with other programmers. |
||
sum += arguments[i]; | ||
} | ||
return sum; | ||
} | ||
console.log('1 + 2 =', sum(1,2)); // = 3 | ||
console.log('1 + 8 + 3 =', sum(1,8,3)); // = 12 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Create a function called vehicle, like before, but takes another parameter called age, so that vehicle("blue", 1, 5) prints 'a blue used car' | ||
|
||
function vehicleType(color,code, age){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also correct, but it's not a good practice to modify the arguments that are passed in the function. Because if you modify a property of that argument in the function, it will also change the property for that argument outside the function. I know this is not the case in this specific function, but it could happen in the future, which could lead to confusing results. For example:
In this code example, the property |
||
if (age < 1) { | ||
age = 'bused' | ||
} else { | ||
age = ' new' | ||
} | ||
|
||
if (code == 1){ | ||
console.log('a ' + color + age + ' car'); | ||
} else if (code == 2) { | ||
console.log('a ' + color + age + ' motorbike'); | ||
} | ||
|
||
} | ||
|
||
vehicleType('blue', 2, 5); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Make a list of vehicles, you can add "motorbike", "caravan", "bike", or more. | ||
|
||
// How do you get the third element from that list? | ||
|
||
// Change the function vehicle to use the list of question 7. So that vehicle("green", 3, 1) prints "a green new bike". | ||
|
||
let vehicles = [' car', ' motorbike', ' bike', ' caraven' ]; | ||
|
||
function vehicleType(color,code, age){ | ||
if (age < 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here the same remark as above (about the bad practice to modify an argument that is passed in the function) |
||
age = ' used' | ||
} else { | ||
age = ' new' | ||
} | ||
|
||
if (code == 1){ | ||
console.log('a ' + color + age + vehicles[0]); | ||
} else if (code == 2) { | ||
console.log('a ' + color + age + vehicles[1]); | ||
} else if (code == 3) { | ||
console.log('a ' + color + age + vehicles[2]); | ||
} else if (code == 4) { | ||
console.log('a ' + color + age + vehicles[3]); | ||
} | ||
|
||
} | ||
|
||
vehicleType('green', 3, 1); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Create a function named vehicleType that receives a color, and a code, 1 for car, 2 for motorbike. And prints 'a blue motorbike' for example when called as vehicleType("blue", 2) | ||
|
||
function vehicleType(color,code){ | ||
if (code == 1){ | ||
console.log('a ' + color + ' car'); | ||
} else if (code == 2) { | ||
console.log('a ' + color + ' motorbike'); | ||
} | ||
} | ||
|
||
|
||
vehicleType('blue', 2); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use
myFavoriteAnimals.push('baby pig')'
. This will work but it's not the correct way to do this.