Cookie Creator
Description:
Cookies: A cookie is a record that the browser keeps, which can store information about your visit to a particular website. The website can create cookies that the browser holds onto that contain information about your visit. If you inspect this page on Chrome, and look in the application tab, you can see the cookies the website is storing about your browsing.
Cookies have the following general format: Name, Value, Domain, Path, ExpirationDate, Size, HTTPOnly, Secure, SameSite.
Cookies are created like this: document.cookie = 'name=value; expires=Thu, 18 Dec 2013 12:00:00; path=/'
etc...
Task:
Write a function that will generate a string representing the code that would create a cookie for you (your function will return a string). For this scenario, we will only worry about the Name, Value, Domain, Path, and Expiration date. Your function should allow those parameters to be passed in, and do the following:
Name : required. If no name is provided, return
'Must include a cookie name'
. This will be passed in as a string.Value : optional. If a value is provided, use that value. If no value is provided, use the name as the value. When provided, this will be passed in as a string.
Expiration Date : optional. If no expiration date is provided, leave it out of the return string entirely. If a date is provided, make sure to allow EITHER a date passed in as a string in the following format:
'mm/dd/yyyy'
OR a number of days, passed as an integer (if passed the integer 30 => create your own date string that is 30 days from now). Either way, the return string would need the date (if included) to look like this format:'Wed Nov 08 2017 17:00:00'
. For the sake of testing, use UTC time.Path : optional. If no path is provided, use
'/'
as the path. If a path is passed in, it will look like'/kata/train'
and will come in as a stringDomain : optional. If no domain is provided, don't include the domain in the cookie string at all. i.e.
document.cookie = "name=value; domain=providedDomain"
VSdocument.cookie = "name=value"
(2nd example left the domain part out completely). When provided, this will be passed in as a string, and will look like:www.example.com
If passed all of these parameters, your function should return a string that looks similar to this:
document.cookie = "name=value; expires=Thu Dec 18 2013 12:00:00; path=/; domain=www.example.com"
Testing:
- All of the tests will expect the order
name=value; expires; path; domain
- Any test that omits one of the parameters will pass null in its place
Similar Kata:
Stats:
Created | Sep 10, 2017 |
Published | Sep 14, 2017 |
Warriors Trained | 471 |
Total Skips | 9 |
Total Code Submissions | 1307 |
Total Times Completed | 101 |
JavaScript Completions | 101 |
Total Stars | 10 |
% of votes with a positive feedback rating | 71% of 31 |
Total "Very Satisfied" Votes | 17 |
Total "Somewhat Satisfied" Votes | 10 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 6 kyu |