Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<title>CS4241 Assignment 2</title>
<meta charset="utf-8">
<link rel="stylesheet" href="styles.css">

<!-- get rid of favicon error -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>
<body>
<div id="mainDiv">
</div>
<button id="createButton">Create new button</button>
<input type="text" id="letterInput" placeholder="Enter a letter">
<script src="main.js"></script>
</body>
</html>
80 changes: 80 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const Artist = {
speak() {
console.log("I am an artist")
}
}

const Painter = {
__proto__ : Artist,

paint() {
document.body.style.backgroundColor = generateColor();
}


}

function generateColor() {
let hexStretch = "0123456789ABCDEF"
let hexString = ""


for (i = 0; i < 6; i++) {
randIndex = Math.floor(Math.random() * hexStretch.length)
hexString += hexStretch[randIndex]

}

return "#" + hexString
}

function generateBlocks() {
const mainDiv = document.getElementById('mainDiv')

for (let i = 0; i < 20; i++) {
const block = document.createElement('div')
block.className = "block"
block.style.backgroundColor = generateColor()
mainDiv.appendChild(block)
}
}


const letterInput = document.getElementById('letterInput');

letterInput.addEventListener('input', function() {
const letter = this.value.trim()
if (letter.length === 1) {
const h1 = document.createElement('h1')
h1.textContent = letter
document.body.appendChild(h1)
this.value = '';
}
});


window.onload = function() {
generateBlocks();

const createButton = document.querySelector('button')
createButton.addEventListener('click', createNewButton)
};

function createNewButton() {
const newButton = document.createElement('button')
newButton.textContent = generateRandomText()
newButton.addEventListener('click', createNewButton)
this.parentNode.insertBefore(newButton, this.nextSibling)
this.remove()
}

function generateRandomText() {
const charString = "abcdef0123456789"
let randomText = ""

for (let i = 0; i < 5; i++) {
randomText += charString.charAt(Math.floor(Math.random() * charString.length))
}

return randomText;
}
5 changes: 5 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.block {
width: 40px;
height: 40px;
display: inline-block;
}