Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a few thousand JPEGs of different animals. I want to show them moving from the left end of the screen to the right in a web browser. At any point of time there may be a few animals or a few hundred on the screen. How can I do this in Javascript?
You can for example use an already animated looped gif of an animal walking. Then you can just change the position of the gif with JS.
var elem = document.getElementById("animal");
var pos = 0;
var id = setInterval(frame, 75);
function frame() {
if (pos >= 100) {
pos = -10;
} else {
pos=pos+0.25;
elem.style.left = pos + '%';
}
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
How do i solve this problem:
if X is 7 or more greater than Y in javascript show green.
if X if from 4-7 greater than Y show blue.
else show red
this is what i have tried so far:
function solve (x,y) {
if(x > (y +7) ){
return "green"
}
else {
return "red";
}
}
Probably because that function isn't closed
By the way you can't say something ISN'T WORKING if you don't provide the complete code that doesn't work and the error
Anyway
The right code would be
function solve (x,y) {
if(x >= (y +7) ){
return "green"
}
else {
return "blue";
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm writting an score board app.
Got two integers, i need to compare them, for example
to know when game should be ended, eg. score = 20:22, 24:26 (score difference to end the game should be equal to two)
How i can make such comparison with js?
You can use split() method to separate scores into two different elements, and then afterwards just compare them.
function isGameOver(score, differenceToWin) {
var scoreArray = score.split(":");
return Math.abs(scoreArray[0] - scoreArray[1]) > differenceToWin;
}
isGameOver('24:26', 2)
EDIT: In case you only need to compare two integers, go ahead and use only the return statement line:
var score1 = 24;
var score2 = 26;
var differenceToWin = 2;
var isGameOver = Math.abs(score1 - score2) > differenceToWin;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have come across this code in a web page from a CTF game:
function conexion() {
var Password = "unescape(String.fromCharCode%2880%2C%20108%2C%2097%2C%20110%29):KZQWYZLOMNUWC===":
for (i = 0; i < Password.length; i++) {
if (Password[i].indexOf(code1) == 0) {
var TheSplit = Password[i].split(":");
var code1 = TheSplit[0];
var code2 = TheSplit[1];
}
}
}
After working a little bit, I have deobfuscated the Password line and obtained:
unescape(String.fromCharCode(80, 108, 97, 110)):KZQWYZLOMNUWC===
which was also translated to Password = "Plan:KZQWYZLOMNUWC===";.
My first reading of the code is that code1 = Plan and code2 = KZQWYZLOMNUWC.
But this is not the correct answer. I’m also not sure how the === operates here.
May you please give me some insights?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I found answers alluding to this question but most of them seemed to be based on jQuery. As an exercise I am building a image slider app in jQuery and then Javascript. I want to understand what jQuery is doing under the hood, and be able to make the decision to use it or not based on the project.
My problem is this: when I click the next button, I want the gallery to slide to the left, and prevImg will be removed, currentImg will become next and so forth. I will then add a li element with the appropriate class nextImg and the image.
Everything is working fine, but the line of code nextImg.appendChild(next_ImgPath) is not appending an image.
function slideAnimSetting(direction) {
counterAction();
if (direction == 1) {
establishImgPaths();
for (var i = 0; i < innerListEl.length; i++) {
leftPosition = innerListEl[i].offsetLeft;
topPosition = innerListEl[i].offsetTop;
Tween.to(innerListEl[i], 1, {left: leftPosition-700});
}; // end for
prevImg.removeAttribute('class');
currentImg.className = 'prevImg';
nextImg.className = 'currentImg';
listEle = document.createElement('li');
listEle.className = 'nextImg';
for (var i = 0; i < innerUlEl.length; i++) {
innerUlEl[i].appendChild(listEle);
}; //end for
nextImg = document.getElementsByClassName('next-img');
nextImg = nextImg[0];
nextImg.appendChild(next_ImgPath);
setImageStyles();
}
}; // end slideAnimSetting
The console.log is telling me that nextImg is undefined.
You gave it a className of nextImg, but you're searching for next-img.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to change constructor base value like I have:
function G()
{
this.speed=1;
}
and var k=new G(); gives me k.speed=1;
now I want that every time I create new G , its speed was like 10;
I tried
G.changeSpeed=function(){this.speed=10;}
G.prototype.changeSpeed=function(){this.speed=10;}
second works on already initialised ones, but first doesn't work at all ( error ).
any way I can do it?
How about:
function G(speed)
{
this.speed = speed;
}
You can do:
var x = new G(1); // x.speed = 1;
var y = new G(2); // y.speed = 2;