Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // alert('Hello World')
- let greeting = "Hello World";
- console.log(greeting);
- // Output age as as variable in the console
- let age = 58;
- console.log(age);
- console.log("My age is " + age);
- //Preferable syntax
- console.log(`My age is ${age}`);
- greeting = `My greeting age is ${age}`;
- console.log(greeting);
- const century = 100;
- let ageToCentury = century-age;
- let message = `I will be ${century} in ${ageToCentury} years`;
- console.log(message);
- // 3 car mf: Ford, Nissan, Tesla
- // model: Escort, Navara, Model S
- // engine type: Petrol, Diesel , Electric
- const mf = ["Ford", "Nissan", "Tesla"];
- const model = ["Escort", "Navara", "Model S"];
- const engineType = ["Petrol", "Diesel", "Electric"];
- for (let i = 0; i < mf.length; i++) {
- const message = `${mf[i]} : ${model[i]} : ${engineType[i]}`;
- console.log(message);
- }
- console.log(`================================`);
- const fleet = [
- ["Ford", "Mondeo", "Petrol"],
- ["Nissan","Quashai", "Diesel"],
- ["Hyundai", "Kona", "Electric"]
- ]
- for(const car of fleet) {
- const message = `${car[0]} : ${car[1]} : ${car[2]}`;
- console.log(message);
- }
- function renderAge(age) {
- const century = 100;
- let ageToCentury = century - age;
- let message = `I will be ${century} in ${ageToCentury} years`;
- console.log(message);
- }
- const listOfAges = [50, 56, 65, 76, 67, 89];
- for (let i = 0; i < listOfAges.length; i++) {
- const currentAge = listOfAges[i];
- renderAge(currentAge);
- }
- // More efficient using the for / of syntax for iterable objects
- // makes a copy
- for(const currentAge of listOfAges) {
- renderAge(currentAge);
- }
- // But if you need the index
- for(const [idx, currentAge] of listOfAges.entries()){
- console.log(`Calling index ${idx}`);
- renderAge(currentAge)
- }
- // 3 car mf: Ford, Nissan, Tesla
- // model: Escort, Navara, Model S
- // engine type: Petrol, Diesel , Electric
- /*
- ["Ford", "Mondeo", "Petrol"],
- ["Nissan","Quashai", "Diesel"],
- ["Hyundai", "Kona", "Electric"]
- */
- // Object syntax - key value pairs
- // keys have no quotes
- // values are in quotes (unless its a variable or a number)
- // values can be arrays as well
- let car = {
- mf: "Ford",
- model: "Mondeo",
- engineType: "Petrol" // elements separated by comma, not semi-colon
- } //notice braces
- function getFleet() {
- const fleet = [
- {
- mf: "Nissan",
- model: "Quashai",
- engineType: "Petrol" // elements separated by comma, not semi-colon
- },
- {
- mf: "Hyundai",
- model: "Kona",
- engineType: "Petrol" // elements separated by comma, not semi-colon
- },
- {
- mf: "Ford",
- model: "Mondeo",
- engineType: "Electric" // elements separated by comma, not semi-colon
- }
- ]
- return fleet;
- }
- for (const car of getFleet()) {
- console.log(`${car.mf} : ${car.model} : ${car.engineType}`);
- }
- function init() {
- console.log("init");
- }
- function ShowMessage() {
- console.log("I am show message");
- document.getElementById("tbAge").value="25";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement