Theme
Primary Color
Lesson 33

Generators Part 2 Functionality And Return

محتوى الدرس

main.js
/*
  Generators Part 2
  Functionality & Return
*/

function orderBook() {

  window.alert("You Clicked On Button To Order A Book");
  console.log("You Clicked On Button To Order A Book");

  window.alert("You Added The Book To Cart");
  console.log("You Added The Book To Cart");

  window.alert("Payment Is Done");
  console.log("Payment Is Done");

}

let ordering = orderBook();

function * orderBook() {

  window.alert("You Clicked On Button To Order A Book");
  console.log("You Clicked On Button To Order A Book");

  window.alert("You Added The Book To Cart");
  console.log("You Added The Book To Cart");

  window.alert("Payment Is Done");
  console.log("Payment Is Done");

}

// let ordering = orderBook();

function * mySkills() {

  yield "HTML";
  yield "CSS";
  yield "PHP";
  yield "Python";
  yield "JavaScript";

}

let theSkills = mySkills(); // Iterator

for (let skill of theSkills) {

  console.log(skill);

}

for (let s of mySkills()) {

  console.log(s);

}

// Test Return 

function * sayNames() {

  yield "Osama";
  yield "Ahmed";
  return "Sayed";
  yield "Eman";

}

let theNames = sayNames();

console.log(theNames.next());
console.log(theNames.next());
console.log(theNames.next());
console.log(theNames.next());