-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddRandomLetters.js
More file actions
23 lines (23 loc) · 896 Bytes
/
Copy pathaddRandomLetters.js
File metadata and controls
23 lines (23 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Function to add provided random letters
* @param {HTMLDivElement} item container html element
*/
import { countLettersToFillDiv } from "./countLettersToFillDiv.js";
import { alphabets } from "./alphabets.js";
import { config } from "./config.js";
export const addRandomLetters = (item) => {
const container = countLettersToFillDiv(
item.getBoundingClientRect().width,
item.getBoundingClientRect().height
);
let words = [];
for (let index = 0; index < container; index++) {
const randomLetter = alphabets[(alphabets.length * Math.random()) | 0];
const randomBold = alphabets[((alphabets.length / 4) * Math.random()) | 0];
if (randomLetter == randomBold) {
words.push(`<strong>${randomLetter}</strong>`);
}
words.push(alphabets[(alphabets.length * Math.random()) | 0]);
}
item.querySelector(config.elementClass).innerHTML = words.join("");
};