Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. // alert('Hello World')
  2.  
  3. let greeting = "Hello World";
  4.  
  5. console.log(greeting);
  6.  
  7. // Output age as as variable in the console
  8.  
  9. let age = 58;
  10.  
  11. console.log(age);
  12.  
  13. console.log("My age is " + age);
  14.  
  15. //Preferable syntax
  16. console.log(`My age is ${age}`);
  17.  
  18. greeting = `My greeting age is ${age}`;
  19. console.log(greeting);
  20.  
  21. const century = 100;
  22. let ageToCentury = century-age;
  23.  
  24. let message = `I will be ${century} in ${ageToCentury} years`;
  25. console.log(message);
  26.  
  27.  
  28. // 3 car mf: Ford, Nissan, Tesla
  29. // model: Escort, Navara, Model S
  30. // engine type: Petrol, Diesel , Electric
  31.  
  32. const mf = ["Ford", "Nissan", "Tesla"];
  33. const model = ["Escort", "Navara", "Model S"];
  34. const engineType = ["Petrol", "Diesel", "Electric"];
  35.  
  36. for (let i = 0; i < mf.length; i++) {
  37. const message = `${mf[i]} : ${model[i]} : ${engineType[i]}`;
  38. console.log(message);
  39. }
  40.  
  41. console.log(`================================`);
  42.  
  43. const fleet = [
  44. ["Ford", "Mondeo", "Petrol"],
  45. ["Nissan","Quashai", "Diesel"],
  46. ["Hyundai", "Kona", "Electric"]
  47. ]
  48.  
  49.  
  50. for(const car of fleet) {
  51.  
  52. const message = `${car[0]} : ${car[1]} : ${car[2]}`;
  53. console.log(message);
  54. }
  55.  
  56. function renderAge(age) {
  57.  
  58. const century = 100;
  59. let ageToCentury = century - age;
  60.  
  61. let message = `I will be ${century} in ${ageToCentury} years`;
  62. console.log(message);
  63. }
  64.  
  65. const listOfAges = [50, 56, 65, 76, 67, 89];
  66.  
  67. for (let i = 0; i < listOfAges.length; i++) {
  68.  
  69. const currentAge = listOfAges[i];
  70. renderAge(currentAge);
  71.  
  72. }
  73.  
  74. // More efficient using the for / of syntax for iterable objects
  75. // makes a copy
  76.  
  77. for(const currentAge of listOfAges) {
  78. renderAge(currentAge);
  79. }
  80.  
  81. // But if you need the index
  82.  
  83. for(const [idx, currentAge] of listOfAges.entries()){
  84. console.log(`Calling index ${idx}`);
  85. renderAge(currentAge)
  86. }
  87.  
  88. // 3 car mf: Ford, Nissan, Tesla
  89. // model: Escort, Navara, Model S
  90. // engine type: Petrol, Diesel , Electric
  91.  
  92. /*
  93. ["Ford", "Mondeo", "Petrol"],
  94. ["Nissan","Quashai", "Diesel"],
  95. ["Hyundai", "Kona", "Electric"]
  96. */
  97.  
  98. // Object syntax - key value pairs
  99. // keys have no quotes
  100. // values are in quotes (unless its a variable or a number)
  101. // values can be arrays as well
  102.  
  103. let car = {
  104. mf: "Ford",
  105. model: "Mondeo",
  106. engineType: "Petrol" // elements separated by comma, not semi-colon
  107.  
  108. } //notice braces
  109.  
  110. function getFleet() {
  111. const fleet = [
  112. {
  113. mf: "Nissan",
  114. model: "Quashai",
  115. engineType: "Petrol" // elements separated by comma, not semi-colon
  116.  
  117. },
  118. {
  119. mf: "Hyundai",
  120. model: "Kona",
  121. engineType: "Petrol" // elements separated by comma, not semi-colon
  122.  
  123. },
  124. {
  125. mf: "Ford",
  126. model: "Mondeo",
  127. engineType: "Electric" // elements separated by comma, not semi-colon
  128.  
  129. }
  130.  
  131. ]
  132. return fleet;
  133. }
  134.  
  135. for (const car of getFleet()) {
  136. console.log(`${car.mf} : ${car.model} : ${car.engineType}`);
  137. }
  138.  
  139. function init() {
  140.  
  141. console.log("init");
  142.  
  143. }
  144.  
  145. function ShowMessage() {
  146.  
  147. console.log("I am show message");
  148.  
  149. document.getElementById("tbAge").value="25";
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement