Best JavaScript code snippet using wpt
script.js
Source:script.js
1window.onload=function(){2 var startBtn=document.getElementById('start');3 4 startBtn.onclick=function(){5 this.style.display='none';6 Game.init(); //游æå¼å§7 }8}9var Game={10 enemy: { //æ人æ°æ®11 e1: {style: 'bee1', blood: 1, speed: 5, score: 1},12 e2: {style: 'bee2', blood: 2, speed: 7, score: 2}13 },14 gk: [15 {16 eMap: [17 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2',18 'e1','e1','e1','e1','e2','e2','e1','e1','e1','e1',19 'e1','e1','e1','e1','e2','e2','e1','e1','e1','e1',20 'e1','e1','e1','e1','e2','e2','e1','e1','e1','e1',21 'e1','e1','e1','e1','e2','e2','e1','e1','e1','e1'22 ],23 column: 10,24 iSpeedX: 10,25 iSpeedY: 1,26 times: 350027 },28 {29 eMap: [30 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2',31 'e1','e2','e1','e2','e1','e1','e2','e1','e2','e1',32 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2',33 'e1','e2','e1','e2','e1','e1','e2','e1','e2','e1',34 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2'35 ],36 column: 10,37 iSpeedX: 13,38 iSpeedY: 1,39 times: 250040 },41 {42 eMap: [43 'e2','e2','e2','e2','e1','e1','e2','e2','e2','e2',44 'e2','e2','e2','e2','e1','e1','e2','e2','e2','e2',45 'e1','e1','e1','e1','e1','e1','e1','e1','e1','e1',46 'e2','e2','e2','e2','e1','e2','e2','e2','e2','e2',47 'e2','e2','e2','e2','e1','e1','e2','e2','e2','e2'48 ],49 column: 10,50 iSpeedX: 15,51 iSpeedY: 2,52 times: 200053 },54 {55 eMap: [56 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2',57 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2',58 'e1','e1','e1','e1','e2','e2','e1','e1','e1','e1',59 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2',60 'e2','e2','e2','e2','e2','e2','e2','e2','e2','e2'61 ],62 column: 10,63 iSpeedX: 20,64 iSpeedY: 3,65 times: 100066 },67 ],68 init: function(){ //åå§å69 this.oParent=document.getElementById('stage');70 this.createScore();71 this.createShooter();72 this.createEnemy(0);73 this.iNow=0; //第å å
³å¡74 },75 createScore: function(){ //积åçå建76 var oS=document.createElement('div');77 oS.id='score';78 oS.innerHTML='积åï¼<span>0<span>';79 this.oParent.appendChild(oS);80 this.oScroe=oS.getElementsByTagName('span')[0];81 },82 createEnemy: function(iNow){ //å建æ人83 if(this.oUl){84 clearInterval(this.oUl.timer);85 this.oParent.removeChild(this.oUl);86 }87 document.title="第"+parseInt(iNow+1)+"å
³";88 var gk=this.gk[iNow];89 var oUl=document.createElement('ul');90 var beePosition=[];91 oUl.id='bees';92 oUl.style.width=gk.column*40+'px';93 this.oParent.appendChild(oUl);94 oUl.style.left=(this.oParent.offsetWidth-oUl.offsetWidth)/2+'px';95 for(var i=0;i<gk.eMap.length;i++){96 var bee=document.createElement('li');97 bee.className=this.enemy[gk.eMap[i]].style;98 bee.blood=this.enemy[gk.eMap[i]].blood;99 bee.speed=this.enemy[gk.eMap[i]].speed;100 bee.score=this.enemy[gk.eMap[i]].score;101 oUl.appendChild(bee);102 }103 this.oUl=oUl;104 this.bees=oUl.getElementsByTagName('li');105 for(var i=0;i<this.bees.length;i++){106 beePosition.push([this.bees[i].offsetLeft,this.bees[i].offsetTop]);107 108 }109 110 for(var i=0;i<this.bees.length;i++){111 this.bees[i].style.float='none';112 this.bees[i].style.position='absolute';113 this.bees[i].style.left=beePosition[i][0]+'px';114 this.bees[i].style.top=beePosition[i][1]+'px';115 }116 this.runEnemy(gk);117 },118 runEnemy: function(gk){ //移å¨æ人119 var This=this;120 var L=0;121 var R=This.oParent.offsetWidth-This.oUl.offsetWidth;122 this.oUl.timer=setInterval(function(){123 if(This.oUl.offsetLeft>R || This.oUl.offsetLeft<L){124 gk.iSpeedX*=-1;125 }126 This.oUl.style.left=This.oUl.offsetLeft+gk.iSpeedX+'px';127 This.oUl.style.top=This.oUl.offsetTop+gk.iSpeedY+'px';128 },200);129 var timer1=setInterval(function(){130 This.oneBeeFly();131 },gk.times);132 133 },134 createShooter: function(){ //å建å°æ135 var oSh=document.createElement('div');136 oSh.id='shooter';137 this.oParent.appendChild(oSh);138 oSh.style.left=(this.oParent.offsetWidth-oSh.offsetWidth)/2+"px";139 oSh.style.top=this.oParent.offsetHeight-oSh.offsetHeight+"px";140 this.oSh=oSh;141 this.runShooter(); 142 },143 runShooter: function(){144 var This=this;145 var timer=null;146 var iNum=0;147 document.onkeydown=function(k){148 //alert(k.keyCode);149 var ev=k || window.event;150 if(!timer){151 if(ev.keyCode==37){152 iNum=1;153 }154 else if(ev.keyCode==39){155 iNum=2;156 }157 timer=setInterval(move,30);158 //alert(k.keyCode);159 } 160 }161 document.onkeyup=function(k){162 var ev=k || window.event;163 clearInterval(timer);164 timer=null;165 iNum=0;166 if(ev.keyCode==32){167 This.createBullet();168 }169 }170 function move(){171 if(iNum==1){172 This.oSh.style.left=This.oSh.offsetLeft-20+'px';173 }174 else if(iNum==2){175 This.oSh.style.left=This.oSh.offsetLeft+20+'px';176 }177 }178 },179 180 createBullet: function(){ //åå¼¹çå建181 var oB=document.createElement('div');182 oB.className='bullet';183 this.oParent.appendChild(oB);184 //alert(this.oSh.offsetLeft);185 oB.style.left=this.oSh.offsetLeft+this.oSh.offsetWidth/2-1+'px';186 oB.style.top=this.oSh.offsetTop-oB.offsetHeight+'px';187 this.runBullet(oB);188 },189 runBullet: function(oB){ //åå¼¹è¿è¡190 var This=this; 191 var timer=null;192 timer=setInterval(function(){193 oB.style.top=oB.offsetTop-10+'px';194 if(oB.offsetTop+oB.offsetHeight<0){195 clearInterval(timer);196 This.oParent.removeChild(oB);197 }198 //alert(This.bees.length);199 for(var i=0;i<This.bees.length;i++){200 var bee=This.bees[i];201 if(This.collisionJudge(bee,oB)){202 This.oParent.removeChild(oB);203 clearInterval(timer);204 bee.blood--;205 if(bee.blood<=0){206 clearInterval(bee.timer);207 This.oUl.removeChild(bee);208 This.oScroe.innerHTML=parseInt(This.oScroe.innerHTML)+bee.score;209 if(This.bees.length==0){210 This.iNow++;211 console.log("iNow:"+This.iNow);212 This.createEnemy(This.iNow);213 }214 } 215 }216 }217 218 },10);219 },220 collisionJudge: function(oM,oN){ //碰æå¤æï¼è¥ç¢°æè¿åtrue221 var a=oM.offsetLeft+this.oUl.offsetLeft;222 var b=oM.offsetTop+this.oUl.offsetTop;223 var w1=oM.offsetWidth;224 var h1=oM.offsetHeight;225 var x=oN.offsetLeft;226 var y=oN.offsetTop;227 var w2=oN.offsetWidth;228 var h2=oN.offsetHeight;229 if(x>a-w2 && x<a+w1 && y>b-h2 && y<b+h1){ 230 return true;231 }232 else{233 return false;234 };235 },236 oneBeeFly: function(){ //éæºä¸é£237 var This=this;238 var bees=this.bees;239 var bee=bees[Math.floor(Math.random()*bees.length)];240 console.log(bee);241 242 bee.timer=setInterval(function(){243 var s=bee.speed;244 var a=This.oSh.offsetLeft+This.oSh.offsetWidth/2;245 var b=This.oSh.offsetTop+This.oSh.offsetHeight/2;246 var x=bee.offsetLeft+bee.offsetWidth/2+This.oUl.offsetLeft;247 var y=bee.offsetTop+bee.offsetHeight/2+This.oUl.offsetTop;248 var A=a-x;249 var B=b-y;250 var C=Math.sqrt(A*A+B*B);251 bee.style.left=bee.offsetLeft+A/C*s+'px';252 bee.style.top=bee.offsetTop+B/C*s+'px';253 if(This.collisionJudge(bee,This.oSh)){254 clearInterval(bee.timer);255 alert("被尼çææ»äº!");256 This.oUl.removeChild(bee);257 window.location.reload();258 }259 },30);260 },...
S7.8.3_A3.3_T1.js
Source:S7.8.3_A3.3_T1.js
1// Copyright 2009 the Sputnik authors. All rights reserved.2// This code is governed by the BSD license found in the LICENSE file.3/**4 * DecimalLiteral :: DecimalIntegerLiteral. ExponentPart5 *6 * @path ch07/7.8/7.8.3/S7.8.3_A3.3_T1.js7 * @description ExponentPart :: e DecimalDigits8 */9//CHECK#010if (0.e1 !== 0) {11 $ERROR('#0: 0.e1 === 0');12}13//CHECK#114if (1.e1 !== 10) {15 $ERROR('#1: 1.e1 === 10');16}17//CHECK#218if (2.e1 !== 20) {19 $ERROR('#2: 2.e1 === 20');20}21//CHECK#322if (3.e1 !== 30) {23 $ERROR('#3: 3.e1 === 30');24}25//CHECK#426if (4.e1 !== 40) {27 $ERROR('#4: 4.e1 === 40');28}29//CHECK#530if (5.e1 !== 50) {31 $ERROR('#5: 5.e1 === 50');32}33//CHECK#634if (6.e1 !== 60) {35 $ERROR('#6: 6.e1 === 60');36}37//CHECK#738if (7.e1 !== 70) {39 $ERROR('#7: 7.e1 === 70');40}41//CHECK#842if (8.e1 !== 80) {43 $ERROR('#8: 8.e1 === 80');44}45//CHECK#946if (9.e1 !== 90) {47 $ERROR('#9: 9.e1 === 90');...
Using AI Code Generation
1const wpt = require('wpt');2const e1 = wpt.e1;3const e2 = wpt.e2;4const e3 = wpt.e3;5const e4 = wpt.e4;6const e5 = wpt.e5;7const e6 = wpt.e6;8const e7 = wpt.e7;9const e8 = wpt.e8;10const e9 = wpt.e9;11const e10 = wpt.e10;12const e11 = wpt.e11;13const e12 = wpt.e12;14const e13 = wpt.e13;15const e14 = wpt.e14;16const e15 = wpt.e15;17const e16 = wpt.e16;18const e17 = wpt.e17;19const e18 = wpt.e18;20const e19 = wpt.e19;21const e20 = wpt.e20;22const e21 = wpt.e21;23const e22 = wpt.e22;24const e23 = wpt.e23;25const e24 = wpt.e24;26const e25 = wpt.e25;27const e26 = wpt.e26;28const e27 = wpt.e27;29const e28 = wpt.e28;30const e29 = wpt.e29;31const e30 = wpt.e30;32const e31 = wpt.e31;33const e32 = wpt.e32;34const e33 = wpt.e33;35const e34 = wpt.e34;36const e35 = wpt.e35;37const e36 = wpt.e36;38const e37 = wpt.e37;39const e38 = wpt.e38;40const e39 = wpt.e39;41const e40 = wpt.e40;42const e41 = wpt.e41;43const e42 = wpt.e42;44const e43 = wpt.e43;45const e44 = wpt.e44;46const e45 = wpt.e45;47const e46 = wpt.e46;48const e47 = wpt.e47;49const e48 = wpt.e48;50const e49 = wpt.e49;51const e50 = wpt.e50;52const e51 = wpt.e51;53const e52 = wpt.e52;54const e53 = wpt.e53;55const e54 = wpt.e54;
Using AI Code Generation
1var wpt = require('wpt');2var e1 = require('e1');3var e2 = require('e2');4var e3 = require('e3');5var e4 = require('e4');6var e5 = require('e5');7var e6 = require('e6');8var e7 = require('e7');9var e8 = require('e8');10var e9 = require('e9');11var e10 = require('e10');12var e11 = require('e11');13var e12 = require('e12');14var e13 = require('e13');15var e14 = require('e14');16var e15 = require('e15');17var e16 = require('e16');18var e17 = require('e17');19var e18 = require('e18');20var e19 = require('e19');21var e20 = require('e20');22var e21 = require('e21');23var e22 = require('e22');24var e23 = require('e23');25var e24 = require('e24');26var e25 = require('e25');27var e26 = require('e26');28var e27 = require('e27');29var e28 = require('e28');30var e29 = require('e29');31var e30 = require('e30');32var e31 = require('e31');33var e32 = require('e32');34var e33 = require('e33');35var e34 = require('e34');36var e35 = require('e35');37var e36 = require('e36');38var e37 = require('e37');39var e38 = require('e38');40var e39 = require('e39');41var e40 = require('e40');42var e41 = require('e41');43var e42 = require('e42');44var e43 = require('e43');45var e44 = require('e44');46var e45 = require('e45');47var e46 = require('e46');48var e47 = require('e47');49var e48 = require('e48');50var e49 = require('e49');51var e50 = require('e50');52var e51 = require('e51');53var e52 = require('e52');54var e53 = require('e53');55var e54 = require('e54');
Using AI Code Generation
1var wptest = require('./wptest.js');2wptest.e1();3var wptest = function() {4 this.e1 = function() {5 console.log('e1');6 }7 this.e2 = function() {8 console.log('e2');9 }10}11module.exports = new wptest();
Using AI Code Generation
1var e1 = require("wpt.js");2console.log(e1.e1(2, 2));3var e2 = require("wpt.js");4console.log(e2.e2(2));5var e3 = require("wpt.js");6console.log(e3.e3(2));7var e4 = require("wpt.js");8console.log(e4.e4(2));9var e5 = require("wpt.js");10console.log(e5.e5(2));11var e6 = require("wpt.js");12console.log(e6.e6(2, 2));13var e7 = require("wpt.js");14console.log(e7.e7(2));15var e8 = require("wpt.js");16console.log(e8.e8([1, 2, 3]));
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!!