Skip to content

Instantly share code, notes, and snippets.

@youaresofunny
Last active January 27, 2019 10:34
Show Gist options
  • Save youaresofunny/22fa6b950836ef93c371dd70ef29afbd to your computer and use it in GitHub Desktop.
Save youaresofunny/22fa6b950836ef93c371dd70ef29afbd to your computer and use it in GitHub Desktop.
function* formGen() {
let name, surename, date;
nameLabel:
while (true) {
name = yield('Enter name');
if (name === 'cancel') return;
surenameLabel:
while (true) {
surename = yield('Enter surename');
if (surename === 'back') continue nameLabel;
dateLabel:
while (true) {
date = yield('Enter date');
if (date === 'back') continue surenameLabel;
break nameLabel;
}
}
}
return { name, surename, date };
}
const form = formGen();
const question = form.next(); //Enter your name
const question2 = form.next('Anton'); //Enter your surename
const question3 = form.next('Lo'); // Enter your birthdate
const backQuestion = form.next('back'); // Enter your surename
const dateQuestion = form.next('Lopan');
const formData = form.next('01.01.01');
console.log(formData) // Anton Lopan 01.01.01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment