SlideShare a Scribd company logo
10 JavaScript Projects - Laurence
Svekis
requestAnimationFrame and
cancelAnimationFrame Code Sample
<!doctype html><html>
<head>
<title>Questions and Answers JavaScript</title>
</head>
<body>
<div class="top">
<div class="nested1">Nested 1</div>
<div class="nested2">Nested 2</div>
<div class="nested3">Nested 3</div>
</div>
<script>
let tog = true;
const div = document.createElement('div');
div.textContent = "hello";
div.style.color = "red";
div.style.position = "absolute";
div.style.left = '50px';
div.x = 50;
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
div.addEventListener('click', stopper);
const topEle = document.querySelector('.top');
topEle.append(div);
let myAni = requestAnimationFrame(mover);
function stopper() {
if (tog) {
cancelAnimationFrame(myAni);
tog = false;
}
else {
tog = true;
myAni = requestAnimationFrame(mover);
}
}
function mover() {
div.x = div.x + 1;
div.style.left = div.x + 'px';
myAni = requestAnimationFrame(mover);
}
</script>
</body>
</html>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
JavaScript Switch Statement
<!doctype html>
<html>
<head>
<title>Questions and Answers JavaScript</title>
</head>
<body>
<div class="top">
<div class="nested1">Nested 1</div>
<div class="nested2">Nested 2</div>
<div class="nested3">Nested 3</div>
</div>
<div class="message">What time is it</div>
<input type="text">
<button>Click</button>
<script>
const btn = document.querySelector('button');
const answer = document.querySelector('input');
const message = document.querySelector('.message');
btn.addEventListener('click', function () {
console.log(answer.value);
//let ans = Number(answer.value);
let ans = parseInt(answer.value);
//console.log(typeof(answer.value));
console.log(typeof (ans));
console.log(ans);
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
if (!Number(ans)) {
console.log('not a number');
}
else {
console.log('Okay');
message.textContent = checkTimeofDay(ans);
}
})
outputToday();
function outputToday() {
const today = new Date().getDay();
let dayName = 'Unknown';
let weekStatus = 'Unknown';
switch (today) {
case 0:
dayName = "Sunday";
break;
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
}
switch (dayName) {
case "Thursday":
case "Friday":
case "Saturday":
weekStatus = "end of Week";
break;
default:
weekStatus = "Start of Week";
}
console.log(today);
message.textContent = `Today is a ${dayName} its the
${weekStatus}`;
}
function checkTimeofDay(num) {
switch (num < 12) {
case true:
return 'Good Morning';
break;
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
case false:
return 'Good Afternoon';
break;
default:
return 'something went wrong'
}
}
</script>
</body>
</html>
Example of using Continue and Break in
For loop and While Loop
<!doctype html>
<html>
<head>
<title>Questions and Answers JavaScript</title>
</head>
<body>
<div class="top">
<div class="nested1">Nested 1</div>
<div class="nested2">Nested 2</div>
<div class="nested3">Nested 3</div>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
</div>
<div class="message">What time is it</div>
<input type="text">
<button>Click</button>
<script>
for (let i = 0; i < 10; i++) {
if (i === 3) {
continue;
}
if (i === 8) {
break;
}
console.log(i);
}
let x = 0;
while (x < 10) {
//if(x===3){continue;}
if (x === 8) {
break;
}
//console.log(x);
x++;
}
//console.log(x);
</script>
</body>
</html>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
Keyboard Event Listeners - Dynamically
Add Page Elements input and divs
<!doctype html><html>
<head>
<title>Questions and Answers JavaScript</title>
</head>
<body>
<script>
const output = document.createElement('div');
const message = document.createElement('div');
const btn = document.createElement('button');
document.body.append(output);
output.append(message);
output.append(btn);
btn.textContent = "Click to add input";
btn.style.backgroundColor = 'red';
btn.style.color = 'white';
btn.style.padding = '10px';
btn.addEventListener('click', maker)
function maker() {
const tempDiv = document.createElement('div');
const newInput = document.createElement('input');
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
output.append(tempDiv);
tempDiv.append(newInput);
newInput.value = 'test';
newInput.hiddenValue =
Math.random().toString(16).substr(-6);
newInput.style.backgroundColor = '#' +
newInput.hiddenValue;
newInput.focus();
newInput.addEventListener('keyup', log);
newInput.addEventListener('keypress', log);
newInput.addEventListener('keydown', function (e) {
console.log(e.keyCode);
if (e.keyCode == 13) {
message.innerHTML += `<div
style="background:#${newInput.hiddenValue}">${newInput.value}</d
iv>`;
}
});
}
function log(event) {
console.log(event);
}
</script>
</body>
</html>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
Create Page Elements add Dynamically
on the Page
<!doctype html><html>
<head>
<title>Questions and Answers JavaScript</title>
</head>
<body>
<script>
const btn = document.createElement('button');
const output = document.createElement('div');
const message = document.createElement('div');
btn.textContent = "Click Me!";
message.textContent = "Hello World";
document.body.append(output);
output.append(message);
output.append(btn);
btn.addEventListener('click', () => {
const today = new Date();
message.textContent = `${today.getHours()}
${today.getMinutes()} ${today.getSeconds()}`;
})
</script>
</body>
</html>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
Pure JavaScript Dice - Create Elements
and Build HTML for Dice
<!doctype html><html>
<head>
<title>Questions and Answers JavaScript</title>
</head>
<body>
<script>
const diceView = [[5], [1, 9], [1, 5, 9], [1, 3, 7, 9],
[1, 3, 5, 7, 9], [1, 3, 4, 6, 7, 9]];
const btn = document.createElement('button');
btn.textContent = "Roll Dice";
const playArea = document.createElement('div');
document.body.prepend(playArea);
playArea.append(btn);
const area1 = document.createElement('div');
const area2 = document.createElement('div');
const container = document.createElement('div');
playArea.append(container);
container.append(area1);
container.append(area2);
area1.textContent = "first Dice";
area2.textContent = "second Dice";
addBorders(area1);
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
addBorders(area2);
btn.addEventListener('click', () => {
rollValue();
console.log(area1.val);
console.log(area2.val);
})
function genDice(val) {
let html = '<div>';
let tempArr = diceView[val];
console.log(tempArr);
for (let x = 1; x < 10; x++) {
let tempVal = 'white';
if (tempArr.includes(x)) {
tempVal = 'black';
}
html += `<span
style="width:90px;display:inline-block;height:90px;border-radius
:20px;background-color:${tempVal};margin:2px;"></span>`;
}
html += '</div>';
return html;
}
function rollValue() {
area1.val = Math.floor(Math.random() * 6);
area2.val = Math.floor(Math.random() * 6);
area1.innerHTML = genDice(area1.val);
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
area2.innerHTML = genDice(area2.val);
}
function addBorders(el) {
el.style.border = '1px solid #ddd';
el.style.borderRadius = "10px";
el.style.padding = '10px';
el.style.fontSize = '1.5em';
el.style.width = '290px';
el.style.height = '290px';
el.style.margin = '10px';
el.style.backgroundColor = 'white';
//el.style.width = '40%';
el.style.float = 'left';
//el.style.height = el.offsetWidth+'px';
}
</script>
</body>
</html>
Create a JavaScript popup Modal
<!doctype html><!doctype html>
<html>
<head>
<title>Course</title>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
<style>
.modal {
position: fixed;
z-index: 5;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.3);
display: none;
}
.modal-body {
background-color: white;
margin: 20% auto;
padding: 20px;
border: 1px solid #333;
border-radius: 25px;
width: 70%;
min-height: 200px;
}
.close {
float: right;
color: red;
font-size: 2em;
font-weight: bold;
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
}
.close:hover {
color: black;
cursor: pointer;
}
</style>
</head>
<body>
<button class='modal1'>Open 1</button>
<button class='modal1'>Open 2</button>
<div class="modal" id="main">
<div class="modal-body"> <span class="close">&times;</span>
<div class="modal-text">Modal Text
<br> test </div>
</div>
</div>
<script>
const btns = document.querySelectorAll('.modal1');
const output = document.querySelector('.modal-text');
btns.forEach((btn) => {
btn.addEventListener('click', (e) => {
myModal.style.display = 'block';
console.log(e.target.textContent);
let val = e.target.textContent;
let html = "";
switch (val) {
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
case 'Open 1':
html = 'Number one is open <h1>ONE</h1>';
break;
case 'Open 2':
html = '<h1>TWO</h1>';
break;
default:
html = '<h1>ERROR</h1>';
}
output.innerHTML = html;
})
})
const closer = document.querySelector('.close');
const myModal = document.querySelector('#main');
closer.addEventListener('click', closeModal);
myModal.addEventListener('click', closeModal);
function closeModal() {
myModal.style.display = 'none';
}
</script>
</body>
</html>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
JavaScript Request Animation Frame
Simple Counter
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>Hello World</h1>
<script>
const output = document.querySelector('h1');
output.textContent = 'Counter';
let reqVal = requestAnimationFrame(step);
let start;
function step(cnt) {
console.log(cnt);
if (start == undefined) {
start = cnt;
}
const val = Math.floor(cnt - start);
const str = String(val);
console.log(str[0]);
const mil = str.slice(1, 4);
console.log(mil);
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
console.log(val);
output.textContent = `${str[0]} : ${mil}`;
if (val < 5000) {
reqVal = requestAnimationFrame(step);
}
}
</script>
</body>
</html>
QuerySelector adding elements
dynamically to page use of NodeList
<!doctype html>
<html>
<head>
<title>Example querySelectorAll</title>
</head>
<body>
<ul></ul>
<input type="text" name="myInput" value="test">
<button>Click Me to add item</button>
<script>
const ul = document.querySelector('ul');
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
const li = document.querySelectorAll('li');
const myInput =
document.querySelector('input[name="myInput"]');
const btn = document.querySelector('button');
let x = 0;
let val = myInput.value;
btn.addEventListener('click', (e) => {
//console.log(e);
x++;
e.target.textContent = 'Clicked ' + x;
addListItem();
})
function addListItem() {
//console.log(myInput.value);
//console.log(val);
console.dir(ul);
console.log(ul.children.length);
console.log(ul.childElementCount);
const lis = document.querySelectorAll('li');
//console.log(lis.length);
if (myInput.value.length > 3 && lis.length < 5) {
const li = document.createElement('li');
li.textContent = myInput.value;
const val1 = ul.appendChild(li);
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
//console.log(val1);
}
}
</script>
</body>
</html>
Adding Event Listeners to All Matching
Elements on Page - Dynamically adding
<!doctype html>
<html>
<head>
<title>Example querySelectorAll Click</title>
<style>
.active {
color: blue;
}
</style>
</head>
<body>
<h1>Hello</h1>
<ul class="myList">
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<script>
const ul = document.querySelector('ul.myList');
const lis = ul.querySelectorAll('li');
const btn = document.createElement('button');
let counter = lis.length;
btn.textContent = 'Click Me';
document.body.append(btn);
btn.addEventListener('click', (e) => {
counter++;
const li = document.createElement('li');
li.acter = 0;
li.textContent = `Value (${counter}) ${li.acter} - `;
li.addEventListener('click', updateItem);
ul.append(li);
})
lis.forEach((li) => {
console.log(li);
li.acter = 0;
li.addEventListener('click', updateItem);
})
function updateItem(e) {
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
const ele = e.target;
console.dir(ele);
ele.acter++;
console.log(ele.acter);
let temp = ele.textContent;
ele.textContent = `${temp} ${ele.acter}`;
ele.classList.toggle('active');
console.log(ele.classList.contains('active'));
}
</script>
</body>
</html>
Code by Laurence Svekis - JavaScript Course https://basescripts.com/
Get the Full Modern Web Development Course at
https://www.udemy.com/course/modern-web-design/
Ad

Recommended

Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
Laurence Svekis ✔
 
Chrome DevTools Introduction 2020 Web Developers Guide
Chrome DevTools Introduction 2020 Web Developers Guide
Laurence Svekis ✔
 
Javascript projects Course
Javascript projects Course
Laurence Svekis ✔
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
Haim Michael
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive Code
Laurence Svekis ✔
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start)
Haim Michael
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
Laurence Svekis ✔
 
Introduction to java_script
Introduction to java_script
Basavaraj Hampali
 
JAVA SCRIPT
JAVA SCRIPT
Mohammed Hussein
 
Java script
Java script
Sukrit Gupta
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOM
Daiwei Lu
 
Java script
Java script
umesh patil
 
22 j query1
22 j query1
Fajar Baskoro
 
How to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Doris Chen
 
Web Projects: From Theory To Practice
Web Projects: From Theory To Practice
Sergey Bolshchikov
 
Data presentation with dust js technologies backing linkedin
Data presentation with dust js technologies backing linkedin
Ruhaim Izmeth
 
Web Components
Web Components
Nikolaus Graf
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
Fajar Baskoro
 
Front End Development: The Important Parts
Front End Development: The Important Parts
Sergey Bolshchikov
 
Difference between java script and jquery
Difference between java script and jquery
Umar Ali
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
Introduction to web components
Introduction to web components
Marc Bächinger
 
Mdst 3559-02-10-jquery
Mdst 3559-02-10-jquery
Rafael Alvarado
 
Web Performance Tips
Web Performance Tips
Ravi Raj
 
JavaScript and jQuery Basics
JavaScript and jQuery Basics
Kaloyan Kosev
 
JavaScript and BOM events
JavaScript and BOM events
Jussi Pohjolainen
 
Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014
Naresha K
 
lec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
Java script Learn Easy
Java script Learn Easy
prince Loffar
 

More Related Content

What's hot (20)

JAVA SCRIPT
JAVA SCRIPT
Mohammed Hussein
 
Java script
Java script
Sukrit Gupta
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOM
Daiwei Lu
 
Java script
Java script
umesh patil
 
22 j query1
22 j query1
Fajar Baskoro
 
How to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Doris Chen
 
Web Projects: From Theory To Practice
Web Projects: From Theory To Practice
Sergey Bolshchikov
 
Data presentation with dust js technologies backing linkedin
Data presentation with dust js technologies backing linkedin
Ruhaim Izmeth
 
Web Components
Web Components
Nikolaus Graf
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
Fajar Baskoro
 
Front End Development: The Important Parts
Front End Development: The Important Parts
Sergey Bolshchikov
 
Difference between java script and jquery
Difference between java script and jquery
Umar Ali
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
Introduction to web components
Introduction to web components
Marc Bächinger
 
Mdst 3559-02-10-jquery
Mdst 3559-02-10-jquery
Rafael Alvarado
 
Web Performance Tips
Web Performance Tips
Ravi Raj
 
JavaScript and jQuery Basics
JavaScript and jQuery Basics
Kaloyan Kosev
 
JavaScript and BOM events
JavaScript and BOM events
Jussi Pohjolainen
 
Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014
Naresha K
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOM
Daiwei Lu
 
How to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Doris Chen
 
Web Projects: From Theory To Practice
Web Projects: From Theory To Practice
Sergey Bolshchikov
 
Data presentation with dust js technologies backing linkedin
Data presentation with dust js technologies backing linkedin
Ruhaim Izmeth
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
Fajar Baskoro
 
Front End Development: The Important Parts
Front End Development: The Important Parts
Sergey Bolshchikov
 
Difference between java script and jquery
Difference between java script and jquery
Umar Ali
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
ghnash
 
Introduction to web components
Introduction to web components
Marc Bächinger
 
Web Performance Tips
Web Performance Tips
Ravi Raj
 
JavaScript and jQuery Basics
JavaScript and jQuery Basics
Kaloyan Kosev
 
Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014
Naresha K
 

Similar to 10 java script projects full source code (20)

lec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
Java script Learn Easy
Java script Learn Easy
prince Loffar
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 
Meta Programming with JavaScript
Meta Programming with JavaScript
jeresig
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
HTML5
HTML5
Brandon Byars
 
JavaScript front end performance optimizations
JavaScript front end performance optimizations
Chris Love
 
CSS framework By Palash
CSS framework By Palash
PalashBajpai
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
Derek Willian Stavis
 
Webpack packing it all
Webpack packing it all
Criciúma Dev
 
Coldfusion with Keith Diehl
Coldfusion with Keith Diehl
Refresh Annapolis Valley
 
Please dont touch-3.6-jsday
Please dont touch-3.6-jsday
Francesco Fullone
 
Scalable vector ember
Scalable vector ember
Matthew Beale
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
Rob Bontekoe
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
What you need to know bout html5
What you need to know bout html5
Kevin DeRudder
 
jQuery
jQuery
PumoTechnovation
 
Wordless, stop writing WordPress themes like it's 1998
Wordless, stop writing WordPress themes like it's 1998
Filippo Dino
 
Javascript first-class citizenery
Javascript first-class citizenery
toddbr
 
lec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
Java script Learn Easy
Java script Learn Easy
prince Loffar
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 
Meta Programming with JavaScript
Meta Programming with JavaScript
jeresig
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
JavaScript front end performance optimizations
JavaScript front end performance optimizations
Chris Love
 
CSS framework By Palash
CSS framework By Palash
PalashBajpai
 
Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
Derek Willian Stavis
 
Webpack packing it all
Webpack packing it all
Criciúma Dev
 
Scalable vector ember
Scalable vector ember
Matthew Beale
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
Rob Bontekoe
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
What you need to know bout html5
What you need to know bout html5
Kevin DeRudder
 
Wordless, stop writing WordPress themes like it's 1998
Wordless, stop writing WordPress themes like it's 1998
Filippo Dino
 
Javascript first-class citizenery
Javascript first-class citizenery
toddbr
 
Ad

More from Laurence Svekis ✔ (19)

Quiz JavaScript Objects Learn more about JavaScript
Quiz JavaScript Objects Learn more about JavaScript
Laurence Svekis ✔
 
JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2
Laurence Svekis ✔
 
JavaScript Lessons 2023
JavaScript Lessons 2023
Laurence Svekis ✔
 
Top 10 Linkedin Tips Guide 2023
Top 10 Linkedin Tips Guide 2023
Laurence Svekis ✔
 
JavaScript Interview Questions 2023
JavaScript Interview Questions 2023
Laurence Svekis ✔
 
Code examples javascript ebook
Code examples javascript ebook
Laurence Svekis ✔
 
Brackets code editor guide
Brackets code editor guide
Laurence Svekis ✔
 
Web hosting get start online
Web hosting get start online
Laurence Svekis ✔
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Web hosting Free Hosting
Web hosting Free Hosting
Laurence Svekis ✔
 
Web development resources brackets
Web development resources brackets
Laurence Svekis ✔
 
Google Apps Script for Beginners- Amazing Things with Code
Google Apps Script for Beginners- Amazing Things with Code
Laurence Svekis ✔
 
Introduction to Node js for beginners + game project
Introduction to Node js for beginners + game project
Laurence Svekis ✔
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
Laurence Svekis ✔
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Laurence Svekis ✔
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
Laurence Svekis ✔
 
Web Development Introduction to jQuery
Web Development Introduction to jQuery
Laurence Svekis ✔
 
WordPress for Entrepreneurs Management of your own website
WordPress for Entrepreneurs Management of your own website
Laurence Svekis ✔
 
Getting to Know Bootstrap for Rapid Web Development
Getting to Know Bootstrap for Rapid Web Development
Laurence Svekis ✔
 
Quiz JavaScript Objects Learn more about JavaScript
Quiz JavaScript Objects Learn more about JavaScript
Laurence Svekis ✔
 
JavaScript Interview Questions 2023
JavaScript Interview Questions 2023
Laurence Svekis ✔
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Web development resources brackets
Web development resources brackets
Laurence Svekis ✔
 
Google Apps Script for Beginners- Amazing Things with Code
Google Apps Script for Beginners- Amazing Things with Code
Laurence Svekis ✔
 
Introduction to Node js for beginners + game project
Introduction to Node js for beginners + game project
Laurence Svekis ✔
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
Laurence Svekis ✔
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
Laurence Svekis ✔
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
Laurence Svekis ✔
 
Web Development Introduction to jQuery
Web Development Introduction to jQuery
Laurence Svekis ✔
 
WordPress for Entrepreneurs Management of your own website
WordPress for Entrepreneurs Management of your own website
Laurence Svekis ✔
 
Getting to Know Bootstrap for Rapid Web Development
Getting to Know Bootstrap for Rapid Web Development
Laurence Svekis ✔
 
Ad

Recently uploaded (20)

This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to use _name_search() method in Odoo 18
How to use _name_search() method in Odoo 18
Celine George
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
How to Add New Item in CogMenu in Odoo 18
How to Add New Item in CogMenu in Odoo 18
Celine George
 
Q1_TLE 8_Week 1- Day 1 tools and equipment
Q1_TLE 8_Week 1- Day 1 tools and equipment
clairenotado3
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
How to use _name_search() method in Odoo 18
How to use _name_search() method in Odoo 18
Celine George
 
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
How to Add New Item in CogMenu in Odoo 18
How to Add New Item in CogMenu in Odoo 18
Celine George
 
Q1_TLE 8_Week 1- Day 1 tools and equipment
Q1_TLE 8_Week 1- Day 1 tools and equipment
clairenotado3
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...
parmarjuli1412
 
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Tanja Vujicic - PISA for Schools contact Info
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 

10 java script projects full source code

  • 1. 10 JavaScript Projects - Laurence Svekis requestAnimationFrame and cancelAnimationFrame Code Sample <!doctype html><html> <head> <title>Questions and Answers JavaScript</title> </head> <body> <div class="top"> <div class="nested1">Nested 1</div> <div class="nested2">Nested 2</div> <div class="nested3">Nested 3</div> </div> <script> let tog = true; const div = document.createElement('div'); div.textContent = "hello"; div.style.color = "red"; div.style.position = "absolute"; div.style.left = '50px'; div.x = 50; Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 2. div.addEventListener('click', stopper); const topEle = document.querySelector('.top'); topEle.append(div); let myAni = requestAnimationFrame(mover); function stopper() { if (tog) { cancelAnimationFrame(myAni); tog = false; } else { tog = true; myAni = requestAnimationFrame(mover); } } function mover() { div.x = div.x + 1; div.style.left = div.x + 'px'; myAni = requestAnimationFrame(mover); } </script> </body> </html> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 3. JavaScript Switch Statement <!doctype html> <html> <head> <title>Questions and Answers JavaScript</title> </head> <body> <div class="top"> <div class="nested1">Nested 1</div> <div class="nested2">Nested 2</div> <div class="nested3">Nested 3</div> </div> <div class="message">What time is it</div> <input type="text"> <button>Click</button> <script> const btn = document.querySelector('button'); const answer = document.querySelector('input'); const message = document.querySelector('.message'); btn.addEventListener('click', function () { console.log(answer.value); //let ans = Number(answer.value); let ans = parseInt(answer.value); //console.log(typeof(answer.value)); console.log(typeof (ans)); console.log(ans); Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 4. if (!Number(ans)) { console.log('not a number'); } else { console.log('Okay'); message.textContent = checkTimeofDay(ans); } }) outputToday(); function outputToday() { const today = new Date().getDay(); let dayName = 'Unknown'; let weekStatus = 'Unknown'; switch (today) { case 0: dayName = "Sunday"; break; case 1: dayName = "Monday"; break; case 2: dayName = "Tuesday"; break; case 3: dayName = "Wednesday"; break; case 4: Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 5. dayName = "Thursday"; break; case 5: dayName = "Friday"; break; case 6: dayName = "Saturday"; break; } switch (dayName) { case "Thursday": case "Friday": case "Saturday": weekStatus = "end of Week"; break; default: weekStatus = "Start of Week"; } console.log(today); message.textContent = `Today is a ${dayName} its the ${weekStatus}`; } function checkTimeofDay(num) { switch (num < 12) { case true: return 'Good Morning'; break; Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 6. case false: return 'Good Afternoon'; break; default: return 'something went wrong' } } </script> </body> </html> Example of using Continue and Break in For loop and While Loop <!doctype html> <html> <head> <title>Questions and Answers JavaScript</title> </head> <body> <div class="top"> <div class="nested1">Nested 1</div> <div class="nested2">Nested 2</div> <div class="nested3">Nested 3</div> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 7. </div> <div class="message">What time is it</div> <input type="text"> <button>Click</button> <script> for (let i = 0; i < 10; i++) { if (i === 3) { continue; } if (i === 8) { break; } console.log(i); } let x = 0; while (x < 10) { //if(x===3){continue;} if (x === 8) { break; } //console.log(x); x++; } //console.log(x); </script> </body> </html> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 8. Keyboard Event Listeners - Dynamically Add Page Elements input and divs <!doctype html><html> <head> <title>Questions and Answers JavaScript</title> </head> <body> <script> const output = document.createElement('div'); const message = document.createElement('div'); const btn = document.createElement('button'); document.body.append(output); output.append(message); output.append(btn); btn.textContent = "Click to add input"; btn.style.backgroundColor = 'red'; btn.style.color = 'white'; btn.style.padding = '10px'; btn.addEventListener('click', maker) function maker() { const tempDiv = document.createElement('div'); const newInput = document.createElement('input'); Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 9. output.append(tempDiv); tempDiv.append(newInput); newInput.value = 'test'; newInput.hiddenValue = Math.random().toString(16).substr(-6); newInput.style.backgroundColor = '#' + newInput.hiddenValue; newInput.focus(); newInput.addEventListener('keyup', log); newInput.addEventListener('keypress', log); newInput.addEventListener('keydown', function (e) { console.log(e.keyCode); if (e.keyCode == 13) { message.innerHTML += `<div style="background:#${newInput.hiddenValue}">${newInput.value}</d iv>`; } }); } function log(event) { console.log(event); } </script> </body> </html> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 10. Create Page Elements add Dynamically on the Page <!doctype html><html> <head> <title>Questions and Answers JavaScript</title> </head> <body> <script> const btn = document.createElement('button'); const output = document.createElement('div'); const message = document.createElement('div'); btn.textContent = "Click Me!"; message.textContent = "Hello World"; document.body.append(output); output.append(message); output.append(btn); btn.addEventListener('click', () => { const today = new Date(); message.textContent = `${today.getHours()} ${today.getMinutes()} ${today.getSeconds()}`; }) </script> </body> </html> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 11. Pure JavaScript Dice - Create Elements and Build HTML for Dice <!doctype html><html> <head> <title>Questions and Answers JavaScript</title> </head> <body> <script> const diceView = [[5], [1, 9], [1, 5, 9], [1, 3, 7, 9], [1, 3, 5, 7, 9], [1, 3, 4, 6, 7, 9]]; const btn = document.createElement('button'); btn.textContent = "Roll Dice"; const playArea = document.createElement('div'); document.body.prepend(playArea); playArea.append(btn); const area1 = document.createElement('div'); const area2 = document.createElement('div'); const container = document.createElement('div'); playArea.append(container); container.append(area1); container.append(area2); area1.textContent = "first Dice"; area2.textContent = "second Dice"; addBorders(area1); Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 12. addBorders(area2); btn.addEventListener('click', () => { rollValue(); console.log(area1.val); console.log(area2.val); }) function genDice(val) { let html = '<div>'; let tempArr = diceView[val]; console.log(tempArr); for (let x = 1; x < 10; x++) { let tempVal = 'white'; if (tempArr.includes(x)) { tempVal = 'black'; } html += `<span style="width:90px;display:inline-block;height:90px;border-radius :20px;background-color:${tempVal};margin:2px;"></span>`; } html += '</div>'; return html; } function rollValue() { area1.val = Math.floor(Math.random() * 6); area2.val = Math.floor(Math.random() * 6); area1.innerHTML = genDice(area1.val); Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 13. area2.innerHTML = genDice(area2.val); } function addBorders(el) { el.style.border = '1px solid #ddd'; el.style.borderRadius = "10px"; el.style.padding = '10px'; el.style.fontSize = '1.5em'; el.style.width = '290px'; el.style.height = '290px'; el.style.margin = '10px'; el.style.backgroundColor = 'white'; //el.style.width = '40%'; el.style.float = 'left'; //el.style.height = el.offsetWidth+'px'; } </script> </body> </html> Create a JavaScript popup Modal <!doctype html><!doctype html> <html> <head> <title>Course</title> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 14. <style> .modal { position: fixed; z-index: 5; left: 0; top: 0; width: 100%; height: 100%; background-color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0.3); display: none; } .modal-body { background-color: white; margin: 20% auto; padding: 20px; border: 1px solid #333; border-radius: 25px; width: 70%; min-height: 200px; } .close { float: right; color: red; font-size: 2em; font-weight: bold; Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 15. } .close:hover { color: black; cursor: pointer; } </style> </head> <body> <button class='modal1'>Open 1</button> <button class='modal1'>Open 2</button> <div class="modal" id="main"> <div class="modal-body"> <span class="close">&times;</span> <div class="modal-text">Modal Text <br> test </div> </div> </div> <script> const btns = document.querySelectorAll('.modal1'); const output = document.querySelector('.modal-text'); btns.forEach((btn) => { btn.addEventListener('click', (e) => { myModal.style.display = 'block'; console.log(e.target.textContent); let val = e.target.textContent; let html = ""; switch (val) { Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 16. case 'Open 1': html = 'Number one is open <h1>ONE</h1>'; break; case 'Open 2': html = '<h1>TWO</h1>'; break; default: html = '<h1>ERROR</h1>'; } output.innerHTML = html; }) }) const closer = document.querySelector('.close'); const myModal = document.querySelector('#main'); closer.addEventListener('click', closeModal); myModal.addEventListener('click', closeModal); function closeModal() { myModal.style.display = 'none'; } </script> </body> </html> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 17. JavaScript Request Animation Frame Simple Counter <!DOCTYPE html> <html> <head> <title>test</title> </head> <body> <h1>Hello World</h1> <script> const output = document.querySelector('h1'); output.textContent = 'Counter'; let reqVal = requestAnimationFrame(step); let start; function step(cnt) { console.log(cnt); if (start == undefined) { start = cnt; } const val = Math.floor(cnt - start); const str = String(val); console.log(str[0]); const mil = str.slice(1, 4); console.log(mil); Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 18. console.log(val); output.textContent = `${str[0]} : ${mil}`; if (val < 5000) { reqVal = requestAnimationFrame(step); } } </script> </body> </html> QuerySelector adding elements dynamically to page use of NodeList <!doctype html> <html> <head> <title>Example querySelectorAll</title> </head> <body> <ul></ul> <input type="text" name="myInput" value="test"> <button>Click Me to add item</button> <script> const ul = document.querySelector('ul'); Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 19. const li = document.querySelectorAll('li'); const myInput = document.querySelector('input[name="myInput"]'); const btn = document.querySelector('button'); let x = 0; let val = myInput.value; btn.addEventListener('click', (e) => { //console.log(e); x++; e.target.textContent = 'Clicked ' + x; addListItem(); }) function addListItem() { //console.log(myInput.value); //console.log(val); console.dir(ul); console.log(ul.children.length); console.log(ul.childElementCount); const lis = document.querySelectorAll('li'); //console.log(lis.length); if (myInput.value.length > 3 && lis.length < 5) { const li = document.createElement('li'); li.textContent = myInput.value; const val1 = ul.appendChild(li); Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 20. //console.log(val1); } } </script> </body> </html> Adding Event Listeners to All Matching Elements on Page - Dynamically adding <!doctype html> <html> <head> <title>Example querySelectorAll Click</title> <style> .active { color: blue; } </style> </head> <body> <h1>Hello</h1> <ul class="myList"> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 21. <li>One</li> <li>Two</li> <li>Three</li> </ul> <script> const ul = document.querySelector('ul.myList'); const lis = ul.querySelectorAll('li'); const btn = document.createElement('button'); let counter = lis.length; btn.textContent = 'Click Me'; document.body.append(btn); btn.addEventListener('click', (e) => { counter++; const li = document.createElement('li'); li.acter = 0; li.textContent = `Value (${counter}) ${li.acter} - `; li.addEventListener('click', updateItem); ul.append(li); }) lis.forEach((li) => { console.log(li); li.acter = 0; li.addEventListener('click', updateItem); }) function updateItem(e) { Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/
  • 22. const ele = e.target; console.dir(ele); ele.acter++; console.log(ele.acter); let temp = ele.textContent; ele.textContent = `${temp} ${ele.acter}`; ele.classList.toggle('active'); console.log(ele.classList.contains('active')); } </script> </body> </html> Code by Laurence Svekis - JavaScript Course https://basescripts.com/ Get the Full Modern Web Development Course at https://www.udemy.com/course/modern-web-design/