|
1 | 1 | // Already have the password stored in a variable; |
2 | | -const password = "Mattcarolus10"; |
| 2 | +// Exercise one: Using console.log and calling function |
| 3 | +// const password = "Mattcarolus10"; |
| 4 | + |
| 5 | +// // Receive the value which the user entered; |
| 6 | +// function checkPassword(userInput) { |
| 7 | + |
| 8 | +// // Compare the two values; |
| 9 | +// if (userInput===password) { |
| 10 | + |
| 11 | +// // If they match print "Correct password entered"; |
| 12 | +// console.log("Correct password entered ") |
| 13 | +// } |
| 14 | + |
| 15 | +// else { |
| 16 | +// // If they don't match print "Incorrect password, please try again"; |
| 17 | +// console.log("Incorrect password, please try again") |
| 18 | +// }; |
| 19 | + |
| 20 | +// }; |
| 21 | +// checkPassword("Mattcarolus10"); |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +// // Exercise 2: Using the variable scope "response" |
| 26 | +// const password2 = "Mattcarolus10"; |
| 27 | + |
| 28 | +// // Receive the value which the user entered; |
| 29 | +// function checkPassword(userInput) { |
| 30 | + |
| 31 | +// // Compare the two values; |
| 32 | +// if (userInput===password2) { |
| 33 | + |
| 34 | +// // If they match print "Correct password entered"; |
| 35 | +// response = "Correct password entered " |
| 36 | +// } |
| 37 | + |
| 38 | +// else { |
| 39 | +// // If they don't match print "Incorrect password, please try again"; |
| 40 | +// response = "Incorrect password, please try again" |
| 41 | +// }; |
| 42 | + |
| 43 | +// }; |
| 44 | +// checkPassword("Mattcarolus"); |
| 45 | +// console.log(response) |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +const password3 = "Mattcarolus10"; |
| 50 | +const output = checkPassword("Mattcarolus10"); |
3 | 51 |
|
4 | 52 | // Receive the value which the user entered; |
5 | 53 | function checkPassword(userInput) { |
| 54 | + let response; |
6 | 55 |
|
7 | 56 | // Compare the two values; |
8 | | -if (userInput===password) { |
| 57 | +if (userInput===password3) { |
9 | 58 |
|
10 | 59 | // If they match print "Correct password entered"; |
11 | | - response = "Correct password entered " |
| 60 | + response = "Correct password entered "; |
12 | 61 | } |
13 | 62 |
|
14 | 63 | else { |
15 | 64 | // If they don't match print "Incorrect password, please try again"; |
16 | | - response = "Incorrect password, please try again" |
17 | | -}; |
| 65 | + response = "Incorrect password, please try again"; |
| 66 | +} |
| 67 | +return response; |
| 68 | +} |
| 69 | +console.log(output); |
| 70 | + |
18 | 71 |
|
19 | | -}; |
20 | | -checkPassword("Mattcarolus"); |
21 | | -console.log(response) |
|
0 commit comments