Best JavaScript code snippet using wpt
slider-about.js
Source:slider-about.js
1//ÑлайдеÑ2function showSlide(element){3 let actualSlide = document.querySelector('.about-company__show');4 actualSlide.classList.remove('about-company__show');5 actualSlide.classList.add('about-company__hidden');6 let findBlock = document.querySelector(`#${element}`);7 findBlock.classList.remove('about-company__hidden');8 findBlock.classList.add('about-company__show');9}10//пагинаÑиÑ11let pages = document.querySelectorAll('.about-company__page')12pages.forEach((el) => {13 el.addEventListener('click', () => {14 let actualPage = document.querySelector('.about-company__active-page');15 actualPage.classList.remove('about-company__active-page');16 el.classList.add('about-company__active-page');17 showSlide(`slide${el.textContent}`);18 })19})20let arrows = document.querySelectorAll('.arrows__btn');21let prev = arrows[0];22let next = arrows[1];23//кликаем впеÑед24next.addEventListener('click', () => {25 let actualNumberButton = document.querySelector('.about-company__active-page').textContent;//Ð½Ð¾Ð¼ÐµÑ Ð°ÐºÑивной кнопки26 let actualButton = document.querySelector('.about-company__active-page');//акÑÐ¸Ð²Ð½Ð°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ° пагинаÑии27 actualButton.classList.remove('about-company__active-page');//акÑÐ¸Ð²Ð½Ð°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ° пагинаÑии ÑÑановиÑÑÑ Ð½ÐµÐ°ÐºÑивной28 let actualSlide = document.querySelector('.about-company__show');//акÑивнÑй Ñлайд29 actualSlide.classList.remove('about-company__show');30 actualSlide.classList.add('about-company__hidden');//акÑивнÑй Ñлайд ÑкÑÑваеÑÑÑ31 let buttons = document.querySelectorAll('.about-company__page')//вÑе кнопки пагинаÑии32 if (actualNumberButton<=buttons.length-1){//еÑли Ð½Ð¾Ð¼ÐµÑ ÐºÐ½Ð¾Ð¿ÐºÐ¸<=длина маÑÑива кнопок-133 let nextButton = buttons[actualNumberButton];//ÑледÑÑÑÐ°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ°34 nextButton.classList.add('about-company__active-page');//ÑледÑÑÑÐ°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ° ÑÑановиÑÑÑ Ð°ÐºÑивной35 let findBlock = document.querySelector(`#slide${+actualNumberButton+1}`);//ÑледÑÑÑий блок36 findBlock.classList.remove('about-company__hidden');37 findBlock.classList.add('about-company__show')//ÑледÑÑÑий блок ÑÑановиÑÑÑ Ð°ÐºÑивнÑм38 } else {39 let nextButton = buttons[0];//ÑледÑÑÑÐ°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ°40 nextButton.classList.add('about-company__active-page');//ÑледÑÑÑÐ°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ° ÑÑановиÑÑÑ Ð°ÐºÑивной41 let findBlock = document.querySelector('#slide1');//ÑледÑÑÑий блок42 findBlock.classList.remove('about-company__hidden');43 findBlock.classList.add('about-company__show');//ÑледÑÑÑий блок ÑÑановиÑÑÑ Ð°ÐºÑивнÑм44 }45})46//кликаем назад47prev.addEventListener('click', () => {48 let actualNumberButton = document.querySelectorAll('.about-company__active-page')[0].textContent;//Ð½Ð¾Ð¼ÐµÑ Ð°ÐºÑивной кнопки49 let actualButton = document.querySelector('.about-company__active-page');//акÑÐ¸Ð²Ð½Ð°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ° пагинаÑии50 actualButton.classList.remove('about-company__active-page');//акÑÐ¸Ð²Ð½Ð°Ñ ÐºÐ½Ð¾Ð¿ÐºÐ° пагинаÑии ÑÑановиÑÑÑ Ð½ÐµÐ°ÐºÑивной51 let buttons = document.querySelectorAll('.about-company__page')//вÑе кнопки пагинаÑии52 let actualSlide = document.querySelector('.about-company__show');//акÑивнÑй Ñлайд53 actualSlide.classList.remove('about-company__show');54 actualSlide.classList.add('about-company__hidden');//акÑивнÑм Ñлайд ÑÑановиÑÑÑ Ð½ÐµÐ°ÐºÑивнÑм55 if (actualNumberButton==1){//еÑли акÑивнÑй Ñлайд = 156 let prevButton = buttons[buttons.length-1];57 prevButton.classList.add('about-company__active-page');58 let findBlock = document.querySelector('#slide3');59 findBlock.classList.remove('about-company__hidden');60 findBlock.classList.add('about-company__show');61 } else {62 let prevButton = buttons[actualNumberButton-2];63 prevButton.classList.add('about-company__active-page');64 let findBlock = document.querySelector(`#slide${+actualNumberButton-1}`);65 findBlock.classList.remove('about-company__hidden');66 findBlock.classList.add('about-company__show');67 }...
state.js
Source:state.js
...31 let x, y;32 do {33 x = Math.floor(Math.random() * 4);34 y = Math.floor(Math.random() * 4);35 } while (this.findBlock(x, y));36 // ! berakunk ide egy 2-est37 const block = document.createElement("div");38 this.board.push(block);39 block.innerText = 2;40 block.dataset.x = x;41 block.dataset.y = y;42 block.style.opacity = 0;43 this.updateBlock(block);44 this.root.append(block);45 setTimeout(function () {46 block.style.opacity = 147 }, 10);48 }49 deleteBlock(block) {50 this.root.removeChild(block);51 this.board.splice(this.board.indexOf(block), 1);52 }53 findBlock(x, y) {54 return this.board.find(block =>55 parseInt(block.dataset.x) === x && parseInt(block.dataset.y) === y56 );57 }58 updateBlock(block) {59 block.style.left = (block.dataset.x * 50) + "px";60 block.style.top = (block.dataset.y * 50) + "px";61 block.style.background = colors[block.innerText];62 }63 moveLeft() {64 for (let x = 1; x < this.width; x++) {65 for (let y = 0; y < this.width; y++) {66 const block = this.findBlock(x, y);67 if (block === undefined) {68 continue;69 }70 // ! amÃg van hova tolni71 while (block.dataset.x > 0 && !this.findBlock(block.dataset.x - 1, y)) {72 // ! 1-el eltolom73 block.dataset.x--;74 }75 this.updateBlock(block);76 // ! ha mellette ugyanolyan van77 const neighborBlock = this.findBlock(block.dataset.x - 1, y);78 if (neighborBlock && neighborBlock.innerText === block.innerText) {79 neighborBlock.innerText *= 2;80 this.deleteBlock(block);81 this.updateBlock(neighborBlock);82 }83 }84 }85 }86 moveRight() {87 for (let x = this.width - 2; x >= 0; x--) {88 for (let y = 0; y < this.height; y++) {89 const block = this.findBlock(x, y);90 if (block === undefined) {91 continue;92 }93 // ! amÃg van hova tolni94 while (block.dataset.x < this.width - 1 && !this.findBlock(+block.dataset.x + 1, y)) {95 // ! 1-el eltolom96 block.dataset.x++;97 }98 this.updateBlock(block);99 // ! ha mellette ugyanolyan van100 const neighborBlock = this.findBlock(+block.dataset.x + 1, y);101 if (neighborBlock && neighborBlock.innerText === block.innerText) {102 neighborBlock.innerText *= 2;103 this.deleteBlock(block);104 this.updateBlock(neighborBlock);105 }106 }107 }108 }109 moveUp() {110 for (let y = 1; y < this.height; y++) {111 for (let x = 0; x < this.width; x++) {112 const block = this.findBlock(x, y);113 if (block === undefined) {114 continue;115 }116 // ! amÃg van hova tolni117 while (block.dataset.y > 0 && !this.findBlock(x, block.dataset.y - 1)) {118 // ! 1-el eltolom119 block.dataset.y--;120 }121 this.updateBlock(block);122 // ! ha mellette ugyanolyan van123 const neighborBlock = this.findBlock(x, block.dataset.y - 1);124 if (neighborBlock && neighborBlock.innerText === block.innerText) {125 neighborBlock.innerText *= 2;126 this.deleteBlock(block);127 this.updateBlock(neighborBlock);128 }129 }130 }131 }132 moveDown() {133 for (let y = this.height - 2; y >= 0; y--) {134 for (let x = 0; x < this.width; x++) {135 const block = this.findBlock(x, y);136 if (block === undefined) {137 continue;138 }139 // ! amÃg van hova tolni140 while (block.dataset.y < this.height - 1 && !this.findBlock(x, +block.dataset.y + 1)) {141 // ! 1-el eltolom142 block.dataset.y++;143 }144 this.updateBlock(block);145 // ! ha mellette ugyanolyan van146 const neighborBlock = this.findBlock(x, +block.dataset.y + 1);147 if (neighborBlock && neighborBlock.innerText === block.innerText) {148 neighborBlock.innerText *= 2;149 this.deleteBlock(block);150 this.updateBlock(neighborBlock);151 }152 }153 }154 }...
Recursion-Cells-in-a-Blob.js
Source:Recursion-Cells-in-a-Blob.js
...10];11const N = grid.length;12let count = 0;13function solution() {14 findBlock(7, 7);15 return count;16}17function findBlock(x, y) {18 if(x < 0 || y < 0 || x >= N || y >= N) {19 return false;20 } else if (grid[x][y] !== 1) {21 return false;22 } else {23 grid[x][y] = 2;24 count++;25 if ((findBlock(x + 1, y) 26 || (findBlock(x, y + 1))27 || (findBlock(x + 1, y + 1))28 || (findBlock(x + 1, y - 1))29 || (findBlock(x, y - 1))30 || (findBlock(x - 1, y - 1))31 || (findBlock(x - 1, y))32 || (findBlock(x - 1, y + 1)))) {33 return true;34 }35 }36}...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.findBlock('www.google.com', function(err, data) {4 if (err) throw err;5 console.log(data);6});7{ statusCode: 200,8 { url: 'www.google.com',
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');11wpt.getLocations(function(err, data) {12 if (err) {13 console.log('Error: ' + err);14 } else {15 console.log(data);16 }17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');20wpt.getTesters(function(err, data) {21 if (err) {22 console.log('Error: ' + err);23 } else {24 console.log(data);25 }26});27var wpt = require('webpagetest');28var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');29wpt.getTesters(function(err, data) {30 if (err) {31 console.log('Error: ' + err);32 } else {33 console.log(data);34 }35});36var wpt = require('webpagetest');37var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');38wpt.getTesters(function(err, data) {39 if (err) {40 console.log('Error: ' + err);41 } else {42 console.log(data);43 }44});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3test.findBlock('www.google.com', function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest');7var test = wpt('www.webpagetest.org');8test.getLocations(function(err, data) {9 console.log(data);10});11var wpt = require('webpagetest');12var test = wpt('www.webpagetest.org');13test.getTesters(function(err, data) {14 console.log(data);15});16var wpt = require('webpagetest');17var test = wpt('www.webpagetest.org');18test.getTesters(function(err, data) {19 console.log(data);20});21var wpt = require('webpagetest');22var test = wpt('www.webpagetest.org');23test.getTesters(function(err, data) {24 console.log(data);25});26var wpt = require('webpagetest');27var test = wpt('www.webpagetest.org');28test.getTesters(function(err, data) {29 console.log(data);30});31var wpt = require('webpagetest');32var test = wpt('www.webpagetest.org');33test.getTesters(function(err, data) {34 console.log(data);35});36var wpt = require('webpagetest');37var test = wpt('www.webpagetest.org');38test.getTesters(function(err, data) {39 console.log(data);40});41var wpt = require('webpagetest');42var test = wpt('www.webpagetest.org');43test.getTesters(function(err, data) {44 console.log(data);45});
Using AI Code Generation
1var wpt = require('./wpt.js');2var block = wpt.findBlock('test');3console.log(block);4module.exports = {5 findBlock: function(blockName){6 return blockName;7 }8}9You can use the require method to import any method from any module, even if the module is not in the same directory as the file you are importing it into. You can also use the require method to import a module that is not in the same
Using AI Code Generation
1var wptoolbox = require('wptoolbox');2var wp = new wptoolbox();3wp.findBlock("Test", function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wptoolbox = require('wptoolbox');11var wp = new wptoolbox();12wp.findBlock("Test", function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wptoolbox = require('wptoolbox');20var wp = new wptoolbox();21wp.findBlock("Test", function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wptoolbox = require('wptoolbox');29var wp = new wptoolbox();30wp.findBlock("Test", function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wptoolbox = require('wptoolbox');38var wp = new wptoolbox();39wp.findBlock("Test", function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wptoolbox = require('wptoolbox');47var wp = new wptoolbox();48wp.findBlock("Test", function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wptoolbox = require('wptoolbox');56var wp = new wptoolbox();57wp.findBlock("Test", function(err, data) {58 if (err) {
Using AI Code Generation
1var options = {2};3webpagetest.findBlock(options, function(err, data) {4 if (err) throw err;5 console.log(data);6});7exports.findBlock = function(options, callback) {8 request(url, function(err, response, body) {9 if (err) throw err;10 var data = JSON.parse(body);11 callback(null, data);12 });13};
Using AI Code Generation
1var testID = wpt.findBlock("test").getTest().getID();2var testID = wpt.findBlock("test").getTest().getID();3var testID = wpt.findBlock("test").getTest().getID();4var testID = wpt.findBlock("test").getTest().getID();5var testID = wpt.findBlock("test").getTest().getID();6var testID = wpt.findBlock("test").getTest().getID();7var testID = wpt.findBlock("test").getTest().getID();8var testID = wpt.findBlock("test").getTest().getID();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!