|
1 | 1 | // ==== Challenge 1: Write your own closure ==== |
2 | 2 | // Write a simple closure of your own creation. Keep it simple! |
| 3 | +function init() { |
| 4 | + let git = {}; |
| 5 | + alert("Welcome to github setup! Let's start by getting your credentials."); |
| 6 | + function mainloop() { |
| 7 | + git.email = prompt("What is your Email?"); |
| 8 | + git.username = prompt("What is your Github Username?"); |
| 9 | + git.password = prompt("What is your Github Password?"); |
| 10 | + let encrypt = ""; |
| 11 | + for (i = 0; i < git.password.length; i++) { |
| 12 | + encrypt += "*"; |
| 13 | + } |
| 14 | + alert( |
| 15 | + `Oh, so your password is: \n\n${git.password} \n\nThanks for sharing!` |
| 16 | + ); |
| 17 | + git.url = `https://github.com/${git.username}`; |
| 18 | + if ( |
| 19 | + confirm( |
| 20 | + `Your github account URL should be:\n\n ${git.url}\n\nIs that correct?` |
| 21 | + ) !== true |
| 22 | + ) { |
| 23 | + git.url = prompt("What is the correct URL for your github account?"); |
| 24 | + } |
| 25 | + if (confirm("Would you like to visit your site now?")) { |
| 26 | + location.assign(git.url); |
| 27 | + alert("Redirecting you now!"); |
| 28 | + return false; |
| 29 | + } else { |
| 30 | + if ( |
| 31 | + confirm( |
| 32 | + `Okay, let make sure we have all of your info.\n\n\n Email: ${ |
| 33 | + git.email |
| 34 | + }\n\n Username: ${git.username}\n\n Password: ${encrypt}\n\n URL: ${ |
| 35 | + git.url |
| 36 | + }\n\n Is this information correct?` |
| 37 | + ) |
| 38 | + ) { |
| 39 | + return true; |
| 40 | + } else { |
| 41 | + alert("Let's start over!"); |
| 42 | + mainloop(); |
| 43 | + } |
| 44 | + } |
| 45 | + return true; |
| 46 | + } |
3 | 47 |
|
4 | | - |
| 48 | + gitinit = () => { |
| 49 | + let item = prompt(`What did you forget already?`).toLowerCase(); |
| 50 | + alert(`Your ${item} is ${git[item]}\n |
| 51 | + Write it down, silly!`); |
| 52 | + if (confirm("Anything else you forgot?")) { |
| 53 | + gitinit(); |
| 54 | + } |
| 55 | + return true; |
| 56 | + }; |
| 57 | + if (mainloop()) { |
| 58 | + return gitinit(); |
| 59 | + } |
| 60 | + return true; |
| 61 | +} |
| 62 | +if (init()) { |
| 63 | + scope(); |
| 64 | +} |
| 65 | +scope = () => { |
| 66 | + let item = prompt("What do you need help remembering?"); |
| 67 | + alert( |
| 68 | + `I'm sorry, I cannot help you find your ${item} because it is ${ |
| 69 | + git[item] |
| 70 | + }, you have already left the scope you were in and due to closure, I can no longer help you with your github credentials. I told you to write them down, but no one ever listens to me!` |
| 71 | + ); |
| 72 | + if ( |
| 73 | + confirm( |
| 74 | + "Do you want to reload the page and start over again with a new github so you can scope it out?" |
| 75 | + ) |
| 76 | + ) { |
| 77 | + location.reload; |
| 78 | + } |
| 79 | +}; |
5 | 80 | /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ |
6 | 81 |
|
7 | | - |
8 | 82 | // ==== Challenge 2: Create a counter function ==== |
9 | 83 | const counter = () => { |
10 | 84 | // Return a function that when invoked increments and returns a counter variable. |
|
0 commit comments