xxxxxxxxxx
/* Question 8 Code/Comments Here */
String.prototype.prefix = function(char){
return char + this;
}
xxxxxxxxxx
/* Question 6 Link Here */
https://codepen.io/gigikaradag/pen/bGvLzBb
xxxxxxxxxx
<!DOCTYPE html>
<html lang="en">
<head>
<style>
[data-color="red"] { color: red; }
[data-color="blue"] { color: blue; }
[data-color="green"] { color: green; }
[data-color="orange"] { color: orange; }
[data-color="purple"] { color: purple; }
</style>
<script>
window.myHandler = function () {
console.log('Click!');
};
window.getRandomNumber = function (max) {
return Math.floor(Math.random() * max)
}
var colors = ['red', 'blue', 'green', 'orange', 'purple'];
window.changeHeadlineColor = function (croHeadline) {
var random = getRandomNumber(5000);
var randomString = random.toString();
setTimeout(() => {
var colorKey = (randomString.length < 4) ? 0 : parseInt(randomString.charAt(0));
croHeadline.setAttribute('data-color', colors[colorKey]);
changeHeadlineColor(croHeadline);
}, random);
};
</script>
<script>
var myDiv = document.getElementById('myDiv');
myDiv.addEventListener('click', function() {
console.log('thanks to the bugs in my code for making me more succesfull Lol')
}, false);
</script>
</head>
<body>
<div id="myDiv">OMG Click me!</div>
<script>
document.querySelector('#myDiv').addEventListener('click', myHandler);
setTimeout(() => {
myDiv.insertAdjacentHTML('beforebegin', '<h1 id="cro-headline" data-color="red">Cro Metrics</h1>');
var croHeadline = document.querySelector('#cro-headline');
changeHeadlineColor(croHeadline);
}, getRandomNumber(5000));
</script>
</body>
</html>
xxxxxxxxxx
/* Question 2 Response Here */
window.myHandler = function() {
console.log('Click!');
console.log("Thanks to the bugs in my code for making me more succesfull");
};
xxxxxxxxxx
/* Question 3 Response Here */
var headLine= document.getElementById("cro-headline");
headline.innerHTML = "<h1> I am the replaced text</h1>";
xxxxxxxxxx
/* Question 4 Answer Here */
var previousColor;
var oldFunction = window.changeHeadlineColor;
window.changeHeadlineColor = function(croHeadline) {
oldFunction(croHeadline);
var currentElement = document.querySelector('#cro-headline');
var currentColor = currentElement.dataset.color;
console.log('Current color: ' + currentColor + ' | Previous Color: ' + previousColor);
xxxxxxxxxx
/* Question 5 Answer Here */
var urls = [
'www.bacondelivery.com/weekly-bacon-delivery/',
'www.bacondelivery.com/daily-bacon-delivery/',
'www.bacondelivery.com/bacon-of-the-month-club/?',
'www.bacondelivery.com/?',
'www.bacondelivery.com/about/',
'www.bacondelivery.com/contact-us/'
];
var regex =/^((?!about|contact-us|(\.com\/\?)).)*$/s;
urls.forEach(function(url) {
console.log(regex.test(url));
if(regex.test(url)){
testProductPage(url);
} else {
return;
}
})
xxxxxxxxxx
/* Question 7 jQuery Here */
$(function() {
$('#bar').find('.foo').css({
'color': 'red',
'border': '1px solid blue'})
.text('new text!')
.click(function() {
$(this).attr('title', 'new title');
$(this).width('100px');
});
});
xxxxxxxxxx
/* Question 7 JavaScript Here */
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("bar").find('.foo').css({
'color': 'red',
'border': '1px solid blue'})
.innerText = 'new text!'
.click(function() {
this.attr('title', 'new title');
this.width('100px');
});
});