You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
2.5 KiB
JavaScript
132 lines
2.5 KiB
JavaScript
1 year ago
|
console.log('hello world');
|
||
|
|
||
|
|
||
|
const firstNum = 8**2;
|
||
|
console.log(firstNum);
|
||
|
|
||
|
const secondNum = Math.pow(8, 2);
|
||
|
console.log(secondNum);
|
||
|
|
||
|
// Template Literal
|
||
|
|
||
|
let name = 'John';
|
||
|
|
||
|
let message = 'HEllo' + name + '! Welcome to programming';
|
||
|
console.log('Message without template literals '+ message);
|
||
|
|
||
|
message = `Hello ${name}! Welcome to programming`;
|
||
|
console.log(`Messagewith template literals: ${message}`);
|
||
|
|
||
|
const anotherMessage =` ${name} attended a math competetion. He won it by solving the problem 8**2 with the solution of ${firstNum}.
|
||
|
`;
|
||
|
console.log(anotherMessage);
|
||
|
|
||
|
|
||
|
const interestRate = .1
|
||
|
const principal = 1000
|
||
|
|
||
|
console.log (`The interest on your saving account is : ${principal*interestRate}`);
|
||
|
|
||
|
const fullName = ['Juan', 'Dela','Cruz'];
|
||
|
console.log(fullName[0]);
|
||
|
console.log(fullName[1]);
|
||
|
console.log(fullName[2]);
|
||
|
|
||
|
console.log(`Hello ${fullName[0]}${fullName[1]}${fullName[2]}!Nice to meet you`);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// arrow function
|
||
|
const hello = () => {
|
||
|
console.log('hello world');
|
||
|
|
||
|
}
|
||
|
hello();
|
||
|
// Pre-Arrow Function
|
||
|
function printFullName(firstName, middleName, lastName){
|
||
|
console.log(firstName + ''+middleName+''+lastName);
|
||
|
}
|
||
|
printFullName('John', 'D','Smith');
|
||
|
|
||
|
|
||
|
// Arrow Function
|
||
|
const printFullName2 = (firstName, middleName, lastName) => {
|
||
|
console.log(firstName + ''+middleName+''+lastName);
|
||
|
}
|
||
|
printFullName('John', 'D','Smith');
|
||
|
|
||
|
// Pre- Arrow Function with loops
|
||
|
|
||
|
const students =['John','Jane','Judy'];
|
||
|
|
||
|
students.forEach(function(student){
|
||
|
console.log(`${student} is a student`)
|
||
|
})
|
||
|
|
||
|
// Arrow function with loops
|
||
|
|
||
|
students.forEach(student => {
|
||
|
console.log (`${student} is a student`)
|
||
|
});
|
||
|
|
||
|
const add = (x, y) =>{
|
||
|
return x + y;
|
||
|
}
|
||
|
let total = add(1,2);
|
||
|
console.log(total)
|
||
|
|
||
|
|
||
|
const greet = (name = 'User') => {
|
||
|
console.log(`Good morning, ${name}`);
|
||
|
}
|
||
|
|
||
|
greet();
|
||
|
greet('John');
|
||
|
|
||
|
// [SECTION] Class-Based Object Blueprints
|
||
|
/*
|
||
|
- Allows creation/instantiation of objects using classes as blueprints
|
||
|
- Syntax:
|
||
|
class ClassName {
|
||
|
constructor(objectPropertyA, objectPropertyB){
|
||
|
this.objectPropertyA = objectPropertyA;
|
||
|
this.objectPropertyB = objectPropertyB
|
||
|
}
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
class Car {
|
||
|
constructor(brand, name, year) {
|
||
|
this.brand = brand;
|
||
|
this.name = name;
|
||
|
this.year = year;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Instantiating an Object
|
||
|
let myCar = new Car();
|
||
|
console.log(myCar)
|
||
|
|
||
|
myCar.brand = "Ford";
|
||
|
myCar.name = "Ranger Raptor";
|
||
|
myCar.year = 2021;
|
||
|
|
||
|
console.log(myCar);
|
||
|
|
||
|
// Creating/instantiating a new object from the Car class with initialized values
|
||
|
const myNewCar = new Car("Toyota", "Vios", 2021);
|
||
|
console.log(myNewCar);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|