Skip to content

Reduced javascript code for same output #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,42 @@ If you like this repo, be sure to ⭐ it.
| 08 | [Password Generator](https://github.com/smthari/Frontend-Projects/tree/master/Password%20generator%20system)| [Live Demo](https://password-generator-system.netlify.app/)| [Tutorial](https://codingbatch.gumroad.com/l/frontendprojects)
| 09 | [Swiper Cards](https://github.com/smthari/Frontend-Projects/tree/master/Swiper%20cards)| [Live Demo](https://swiper-card.netlify.app/)| [Tutorial](https://codingbatch.gumroad.com/l/frontendprojects)
| 10 | [Todo App](https://github.com/smthari/Frontend-Projects/tree/master/Todo-app)| [Live Demo](https://responsive-todoapp.netlify.app/)| [Tutorial](https://codingbatch.gumroad.com/l/frontendprojects)


In the slide show project, I reduced the size of javascript code for the same output.

<pre> <script>

let slideIndex = 1;


const slides = document.getElementsByClassName("mySlides");



function showSlides(n) {
if (n > slides.length) slideIndex = 1;
if (n < 1) slideIndex = slides.length;

for (let slide of slides) slide.style.display = "none";
slides[slideIndex - 1].style.display = "block";
}

function changeSlide(n) {
showSlides(slideIndex += n);
}

showSlides(slideIndex);


document.addEventListener("contextmenu", e => e.preventDefault());
document.onkeydown = e => {
if (
e.keyCode === 123 || // F12
(e.ctrlKey && e.shiftKey && (e.keyCode === 73 || e.keyCode === 74)) ||
(e.ctrlKey && e.keyCode === 85)
) {
return false;
}
}
</script> </pre>