Skip to content

Conversation

@Samyak2
Copy link
Contributor

@Samyak2 Samyak2 commented Oct 5, 2019

Save and load options using cookies

  • Fixed Add a cookie to remember the user's last dropdown choices #30 .
  • Added onload attributes to each of the select tags.
  • Added a script at the end of body which contains:
    • setCookie - function that takes name, value and number of days until the cookie expires and sets a cookie with those parameters.
    • getCookie - function which returns the cookie value given the name.
    • saveOptionsAsCookie - function to set a cookie with the element's id as name and element's value as value.
    • getOptionsFromCookies - function to get the saved options from the cookies and set them. It also calls the run() function to regenerate the mystery egg

@Samyak2 Samyak2 requested a review from bsoyka as a code owner October 5, 2019 17:26
var select_second = document.getElementById("second-select");
select_first.value = getCookie("first-select");
select_second.value = getCookie("second-select");
run();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a silly question, but may I ask why this run(); line is here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The run(); line is to generate the Mystery Egg again after loading the cookied options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the Randomize button is calling run() function, and I wanted to regenerate or randomize the mystery egg after loading the cookies.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yep, got it.

Copy link
Owner

@bsoyka bsoyka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for your help!

@bsoyka bsoyka merged commit b9ea65a into bsoyka:master Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a cookie to remember the user's last dropdown choices

2 participants