Skip to content

Commit 2097137

Browse files
committed
Added main loop for github credentials
1 parent fafd838 commit 2097137

2 files changed

Lines changed: 79 additions & 5 deletions

File tree

‎assignments/closure.js‎

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,84 @@
11
// ==== Challenge 1: Write your own closure ====
22
// 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+
}
347

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+
};
580
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
681

7-
882
// ==== Challenge 2: Create a counter function ====
983
const counter = () => {
1084
// Return a function that when invoked increments and returns a counter variable.

‎assignments/index.html‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
<title>JS II</title>
99

10-
<script src="array-methods.js"></script>
11-
<script src="callbacks.js"></script>
10+
<!-- <script src="array-methods.js"></script>
11+
<script src="callbacks.js"></script> -->
1212
<script src="closure.js"></script>
13-
<script src="stretch-function-conversion.js"></script>
13+
<!-- <script src="stretch-function-conversion.js"></script> -->
1414
</head>
1515

1616
<body>

0 commit comments

Comments
 (0)