Skip to content

Commit dc9f26a

Browse files
committed
Applied prettier linting and added gitignore.
1 parent bd92cad commit dc9f26a

File tree

6 files changed

+169
-163
lines changed

6 files changed

+169
-163
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.json
2+
node_modules/
3+
.prettierrc

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ This generates a list of factors of a given integer similarly to factors.py but
2020

2121
## word_counter.py
2222

23-
This short simple program counts words in a given string. I use it in command line to quickly see how long any document or paragraph is.
23+
This short simple program counts words in a given string. I use it in command line to quickly see how long any document or paragraph is.
2424

2525
## randStringGenerator.html and randStringGenerator.js
2626

2727
This is functionally the same as rand_str_gen.py but in javascript. The html page allows the user to input the desired length of string and then it returns a randomly generated string below the input. It also allows the user to tick a box to include spaces in the outputted string to effectively give a paragraph output. The chance of a char being a space is 1 in 6.
2828

2929
## passwordCheck.html and passwordCheck.js
3030

31-
This is a mock up registration page which displays the remaing password complexity requirements and removes them once they're met. It also disables the register button until all the requirements are met and the password confirmation matches.
31+
This is a mock up registration page which displays the remaing password complexity requirements and removes them once they're met. It also disables the register button until all the requirements are met and the password confirmation matches.

passwordCheck.html

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,59 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<script src="passwordCheck.js"></script>
8-
8+
99
<title>Password checker</title>
1010
<style>
11-
*{
12-
margin: 4px;
13-
}
11+
* {
12+
margin: 4px;
13+
}
1414
</style>
15-
</head>
16-
<body>
15+
</head>
16+
<body>
1717
<form>
18-
<div>
19-
<input id="username" type="text" name="username" autofocus autocomplete="off" placeholder="username">
20-
</div>
21-
<div>
22-
<input id="password" type="password" name="password" autocomplete="off" placeholder="password">
23-
</div>
24-
<div>
25-
<input id="confirmation" type="password" name="confirmation" autocomplete="off" placeholder="Confirm password">
26-
</div>
27-
<button id="registerBtn" type="submit">Register</button>
18+
<div>
19+
<input
20+
id="username"
21+
type="text"
22+
name="username"
23+
autofocus
24+
autocomplete="off"
25+
placeholder="username"
26+
/>
27+
</div>
28+
<div>
29+
<input
30+
id="password"
31+
type="password"
32+
name="password"
33+
autocomplete="off"
34+
placeholder="password"
35+
/>
36+
</div>
37+
<div>
38+
<input
39+
id="confirmation"
40+
type="password"
41+
name="confirmation"
42+
autocomplete="off"
43+
placeholder="Confirm password"
44+
/>
45+
</div>
46+
<button id="registerBtn" type="submit">Register</button>
2847
</form>
2948
<ul>
30-
<li id="ReqLen" hidden>Password must be at least 8 characters.</li>
31-
<li id="ReqUpper" hidden>Password must contain 1 upper case character.</li>
32-
<li id="ReqLower" hidden>Password must contain 1 lower case character.</li>
33-
<li id="ReqMatch" hidden> Passwords must match</li>
49+
<li id="ReqLen" hidden>Password must be at least 8 characters.</li>
50+
<li id="ReqUpper" hidden>
51+
Password must contain 1 upper case character.
52+
</li>
53+
<li id="ReqLower" hidden>
54+
Password must contain 1 lower case character.
55+
</li>
56+
<li id="ReqMatch" hidden>Passwords must match</li>
3457
</ul>
35-
36-
</body>
37-
</html>
58+
</body>
59+
</html>

passwordCheck.js

Lines changed: 73 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,89 @@
22
// at least 8 characters
33
// Upper case and lower
44

5-
function checkPassword(password){
6-
let hasLower = 0
7-
let hasUpper = 0
5+
function checkPassword(password) {
6+
let hasLower = 0;
7+
let hasUpper = 0;
88

9-
for(let i = 0; i < password.length; i++) {
9+
for (let i = 0; i < password.length; i++) {
10+
asciiChar = password.charCodeAt(i);
1011

11-
asciiChar = password.charCodeAt(i)
12-
13-
if (asciiChar >= 65 && asciiChar <= 90){
14-
15-
hasUpper += 1
16-
17-
}else if(asciiChar >= 97 && asciiChar <= 122){
18-
19-
hasLower += 1
20-
21-
}
22-
}
23-
24-
let ReqLen = document.querySelector('#ReqLen');
25-
let ReqUpper = document.querySelector('#ReqUpper');
26-
let ReqLower = document.querySelector('#ReqLower');
27-
28-
if (!hasLower){
29-
ReqLower.hidden = false;
30-
}else{
31-
ReqLower.hidden = true;
32-
}
33-
34-
if(!hasUpper){
35-
ReqUpper.hidden = false;
36-
}else{
37-
ReqUpper.hidden = true;
38-
}
39-
40-
if(password.length < 8){
41-
ReqLen.hidden = false;
42-
}else{
43-
ReqLen.hidden = true;
44-
}
45-
46-
if(hasUpper && hasLower && password.length >= 8){
47-
48-
//console.log('password is good')
49-
return 1
50-
}else{
51-
return 0
12+
if (asciiChar >= 65 && asciiChar <= 90) {
13+
hasUpper += 1;
14+
} else if (asciiChar >= 97 && asciiChar <= 122) {
15+
hasLower += 1;
5216
}
17+
}
18+
19+
let ReqLen = document.querySelector("#ReqLen");
20+
let ReqUpper = document.querySelector("#ReqUpper");
21+
let ReqLower = document.querySelector("#ReqLower");
22+
23+
if (!hasLower) {
24+
ReqLower.hidden = false;
25+
} else {
26+
ReqLower.hidden = true;
27+
}
28+
29+
if (!hasUpper) {
30+
ReqUpper.hidden = false;
31+
} else {
32+
ReqUpper.hidden = true;
33+
}
34+
35+
if (password.length < 8) {
36+
ReqLen.hidden = false;
37+
} else {
38+
ReqLen.hidden = true;
39+
}
40+
41+
if (hasUpper && hasLower && password.length >= 8) {
42+
//console.log('password is good')
43+
return 1;
44+
} else {
45+
return 0;
46+
}
5347
}
5448

55-
document.addEventListener('DOMContentLoaded',() => {
56-
57-
console.log(document.title)
58-
59-
// disable reqister button
60-
document.querySelector('#registerBtn').disabled = 'true'
61-
62-
document.querySelector('#password').disabled = true
63-
64-
document.querySelector('#confirmation').disabled = true
49+
document.addEventListener("DOMContentLoaded", () => {
50+
console.log(document.title);
6551

66-
document.onkeyup = () => {
52+
// disable reqister button
53+
document.querySelector("#registerBtn").disabled = "true";
6754

68-
if(document.querySelector('#username').value != ''){
69-
document.querySelector('#password').disabled = false
70-
}
55+
document.querySelector("#password").disabled = true;
7156

72-
if(document.querySelector('#password').value.length >= 8){
73-
document.querySelector('#confirmation').disabled = false
74-
}
57+
document.querySelector("#confirmation").disabled = true;
7558

59+
document.onkeyup = () => {
60+
if (document.querySelector("#username").value != "") {
61+
document.querySelector("#password").disabled = false;
7662
}
77-
78-
document.querySelector('#password').onkeyup = () => {
79-
80-
let password = document.querySelector('#password').value
81-
checkPassword(password)
8263

64+
if (document.querySelector("#password").value.length >= 8) {
65+
document.querySelector("#confirmation").disabled = false;
8366
}
84-
85-
document.querySelector('#confirmation').onkeyup = () => {
86-
87-
if(document.querySelector('#username').value != '' && checkPassword(document.querySelector('#password').value) && document.querySelector('#confirmation').value == document.querySelector('#password').value){
88-
89-
document.querySelector('#registerBtn').disabled = false
90-
document.querySelector('#ReqMatch').hidden = true
91-
92-
console.log('ready to submit')
93-
}else{
94-
95-
document.querySelector('#ReqMatch').hidden = false
96-
document.querySelector('#registerBtn').disabled = true
97-
98-
}
67+
};
68+
69+
document.querySelector("#password").onkeyup = () => {
70+
let password = document.querySelector("#password").value;
71+
checkPassword(password);
72+
};
73+
74+
document.querySelector("#confirmation").onkeyup = () => {
75+
if (
76+
document.querySelector("#username").value != "" &&
77+
checkPassword(document.querySelector("#password").value) &&
78+
document.querySelector("#confirmation").value ==
79+
document.querySelector("#password").value
80+
) {
81+
document.querySelector("#registerBtn").disabled = false;
82+
document.querySelector("#ReqMatch").hidden = true;
83+
84+
console.log("ready to submit");
85+
} else {
86+
document.querySelector("#ReqMatch").hidden = false;
87+
document.querySelector("#registerBtn").disabled = true;
9988
}
100-
101-
102-
})
89+
};
90+
});

randStringGenerator.html

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Random string generator</title>
88
<script src="randStringGenerator.js"></script>
9-
</head>
10-
<body>
9+
</head>
10+
<body>
1111
<h3>Please give the required length of string</h3>
12-
13-
<input id="stringLength" type="number" autofocus> Hit ENTER to refresh
14-
<input type="checkbox" name="spaceToggle" id="spaceToggle">
12+
13+
<input id="stringLength" type="number" autofocus /> Hit ENTER to refresh
14+
<input type="checkbox" name="spaceToggle" id="spaceToggle" />
1515
<label for="spaceToggle">Spaces included?</label>
1616
<p id="result"></p>
17-
18-
</body>
19-
</html>
17+
</body>
18+
</html>

randStringGenerator.js

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
1-
21
// this fn generates a character which can only be a lower case letter
3-
function generatedChar(){
4-
return Math.floor(Math.random() * 26) + 97;
5-
}
6-
2+
function generatedChar() {
3+
return Math.floor(Math.random() * 26) + 97;
4+
}
75

8-
96
// this fn generates a string of given length using the above char generator
10-
function generatedString(length, spaces){
11-
12-
13-
let generatedString = [];
14-
let i = 0;
15-
for(i = 0; i<length; i++){
16-
17-
let new_char = generatedChar();
18-
19-
if (spaces){
20-
if(Math.floor((Math.random() * 6) + 1)===1){
21-
console.log('space test')
22-
new_char = 32
23-
}
24-
}
25-
generatedString.push(String.fromCharCode(new_char));
26-
7+
function generatedString(length, spaces) {
8+
let generatedString = [];
9+
let i = 0;
10+
for (i = 0; i < length; i++) {
11+
let new_char = generatedChar();
12+
13+
if (spaces) {
14+
if (Math.floor(Math.random() * 6 + 1) === 1) {
15+
console.log("space test");
16+
new_char = 32;
17+
}
2718
}
19+
generatedString.push(String.fromCharCode(new_char));
20+
}
2821

29-
// this converts the array into a string
30-
let word = generatedString.join('');
22+
// this converts the array into a string
23+
let word = generatedString.join("");
3124

32-
return word
25+
return word;
3326
}
3427

35-
36-
document.addEventListener('DOMContentLoaded', () => {
37-
38-
document.onkeyup = () => {
39-
let stringLength = document.querySelector('#stringLength').value
40-
let spaces = document.querySelector('#spaceToggle').checked
41-
document.querySelector('#result').innerHTML = generatedString(stringLength, spaces)
42-
}
43-
})
28+
document.addEventListener("DOMContentLoaded", () => {
29+
document.onkeyup = () => {
30+
let stringLength = document.querySelector("#stringLength").value;
31+
let spaces = document.querySelector("#spaceToggle").checked;
32+
document.querySelector("#result").innerHTML = generatedString(
33+
stringLength,
34+
spaces,
35+
);
36+
};
37+
});

0 commit comments

Comments
 (0)