Change inner html every x seconds [closed] - javascript

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 2 years ago.
Improve this question
how to change itens in a table with javascript, every 15 seconds using uinnerHTML:
document.getElementById("iten1").innerHTML = "Bla Bla Bla";

You can create a recursive timeout loop.
function timeout() {
setTimeout(function () {
// Do Something Here
// Then recall the parent function to
// create a recursive loop.
timeout();
}, 1000);
}
If you're new to setTimeout() MDN has a pretty straightforward guide you can play around with. : setTimeout MDN

Related

how to write a complex form of setTimeOut and setTimeInterval with and without recursion? [closed]

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 4 months ago.
Improve this question
function sayHello() {
alert('Hello');
}
setTimeout(sayHello, 1000);
This is a basic setTimeout example, but can I get an in-depth explanation like a long one how it works with recursion and without recursion in javascript? (visualization helps as snippet code too)
You can call setTimeout() again inside the callback. This will print Hello in 1 second, then print World 2 seconds after that.
function sayHello() {
console.log('Hello');
setTimeout(sayWorld, 2000);
}
function sayWorld() {
console.log('World');
}
setTimeout(sayHello, 1000);

why the setInterval method gets 10 as input variable? [closed]

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 1 year ago.
Improve this question
my stopwatch with javascript and I don't get this point
buttonStart.addEventListener("click", () => {
if (Interval) {
clearInterval(Interval); }
Interval = setInterval(startTimer, 10); });
The second value it receives is the number of milliseconds between repetitions. Meaning each 10 milliseconds it will run the startTimer function.

How can I detect if user has successfully alerted a thing (I'm making an XSS game) [closed]

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 2 years ago.
Improve this question
The page just echoes the user input using GET. I have no idea on what concept to apply to detect if the user has alerted something
The easiest approach would probably be to replace the alert method with your own.
const log = [];
alert = function(alert) {
return (value) => {
log.push(value);
alert(value);
};
}(alert);
alert("Hello!");
console.log(log);

How to set variable of image src and use in javascript function? [closed]

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 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
So if i have some codes like this
If(sceneA){document.getElementById("divA").src="A.png";}
If(document.getElementById("divC")=="A.png"){document.getElementById("divB").src="B.png";}//And alot of codes here
How can I use a var to shorten strings like
document.getElementById("divA").src="A.png"
document.getElementById("divB").src="B.png"
so i can use them both inside (IF) and {function}
As they have to repeat quite a few times in the codes.
Thanks alot!
That's exactly what functions are for.
Define a function for repeating blocks of code as follows:
function setSrc(divName, imgName){
document.getElementById("div"+divName).src = imgName+".png";
}
function srcEquals(divName, imgName){
return (document.getElementById("div"+divName).src == imgName+".png");
}
Then you can replace your code with this:
if(sceneA){setSrc("A","A");}
if(srcEquals("C", "A")){setSrc("B","B");}

Inherit nearly all from a first function [closed]

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 5 years ago.
Improve this question
Hello I'm trying to make DRY code (not repeat code) from the a secondFunction that inherits NEARLY all the content from a firstFunction.
This would be the example of what I want but it's not DRY:
function firstFunction(){
this.arrayObjectsToElastic = ["hello1", "hello2"]
this.anothervariable1= "anothervariable1"
this.anothervariable2= "anothervariable2"
this.targetVariableToRemove = "something"
return [this.arrayObjectsToElastic]
}
function secondFunction(){
this.arrayObjectsToElastic = ["hello1", "hello2"]
this.anothervariable1= "anothervariable1"
this.anothervariable2= "anothervariable2"
return [this.arrayObjectsToElastic]
}
Therefore, I don't want to "inherit" in the secondFunction the targetVariableToRemove from the firstFunction because if so it'll crash in some other processes I'm running.
Maybe you can do something like:
function secondFunction(){
return firstFunction().concat(["newContent"]);
}

Categories

Resources