This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<link rel="stylesheet" href="style.css" /> | |
<title>Guess My Number!</title> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<link rel="stylesheet" href="style.css" /> | |
<title>Pig Game</title> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const maskCreditCard = function (number) { | |
const str = number + ''; | |
const last = str.slice(-4); | |
if (str.length !== 16) { | |
return ('The credit card number is incorrect'); | |
} else { | |
return last.padStart(str.length, '*'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const capitaliizeName = function (name) { | |
const names = name.split(' '); | |
const namesUpper = []; | |
for (const n of names) { | |
// namesUpper.push(n[0].toUpperCase() + n.slice(1)); | |
namesUpper.push(n.replace(n[0], n[0].toUpperCase())); | |
} | |
return (namesUpper.join(' ')); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const checkBaggage = function (items) { | |
const baggage = items.toLowerCase(); | |
if (baggage.includes('knife') || baggage.includes('gun')) { | |
return ('You are NOT allowed on board'); | |
} else { | |
return ('Welcome aboard'); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.body.append(document.createElement('textarea')); | |
document.body.append(document.createElement('button')); | |
document.querySelector('button').addEventListener('click', function () { | |
const text = document.querySelector('textarea').value; | |
const rows = text.split('\n'); | |
for (const [i, row] of rows.entries()) { | |
const [first, second] = row.toLowerCase().trim().split('_'); | |
const output = `${first}${second.replace(second[0], second[0].toUpperCase())}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomInt = (min, max) => Math.floor(Math.random() * (max - min) + 1) + min; | |
console.log(randomInt(10, 20)); | |
// Used floor instead of trunc so negative numbers can be used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const formatCurrency = function (value, locale, currency) { | |
new Intl.NumberFormat(locale, { | |
style: 'currency', | |
currency: currency, | |
}).format(value); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const header = document.querySelector('.header'); | |
const navHeight = nav.getBoundingClientRect().height; | |
const stickyNav = function (entries) { | |
const [entry] = entries; | |
if (!entry.isIntersecting) nav.classList.add('sticky'); | |
else nav.classList.remove('sticky'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const imgTargets = document.querySelectorAll('img[data-src]'); | |
const loadImg = function (entries, observer) { | |
const [entry] = entries; | |
if (!entry.isIntersecting) return; | |
entry.target.src = entry.target.dataset.src; | |
entry.target.addEventListener('load', function () { | |
entry.target.classList.remove('lazy-img'); |