Javascript, how do I make it loop this? [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 9 years ago.
Improve this question
So I wish to loop the javascript going to a certain page (without actually reloading/clearing console), then execute
href="javascript:doSomething(9)"
and then loop that by doing a function
Please help, thanks!

Assuming you want it to repeat - you can use an interval.
setInterval(function(){
doSomething(9);
},100); // the 100 is for 100 miliseconds
If you want it to repeat without having to wait (that is, block the code) you can use a normal while loop:
while(true){ // will loop forever since the condition is always "true"
doSomething(9);
}

Related

How to auto run a code multiple times on a site [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
I am looking for a javascript code which will automatically run itself multiple times on a site when i enter it in console . I have already tried and it works only once. Is there any way to automatically run it again and again ?
You can use setInterval function.
Example:
function myFunction(){
console.log('Success!');
}
setInterval(function(){
myFunction();
}, 3000); //you can set the interval here.

How to execute function on specific interval of time in angular [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
I want to execute function in angular on a specific time interval and how can we stop that too. Please give me solution for that.
Your question seems to be about JavaScript in general, not specifically Angular.
You could use setInterval and clearInterval to execute a function on a fixed interval:
// Will print each second
let interval = setInterval(() => console.log("I am a text"), 1000)
// Stops the interval
clearInterval(interval)
Documentation: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval

Using for loop in javascript for 50k time without hanging of browser [closed]

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 5 years ago.
Improve this question
I have to run a loop for 50,000 times, but it is hanging browser. what could be the best way to do it.
sample :
for(var i=0;i<50000;i++)
{
// Here I am calculating 50 different values.
}
I can't use php because values are displayed directly in html page.
what I can do for it?
thanks
You could try a webworker. Here is a package that might simplify things for you.

How to refresh a javascript variable in relation of time without refreshing the page? [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
In an unknown time the variable it deals with get a new value. I would like to refresh the output at the page withoout reloading it every 10 seconds.
How to? Please help.
you can use something like setInterval, https://www.w3schools.com/jsref/met_win_setinterval.asp
setInterval(function() {
//do what you need to with the variable here
}, 10 * 1000); //since millseconds
Use setInterval.
setInterval(function() {
}, 10*1000)
as said.
BUT...
If the new value of the variable, has to do with time, you 'd better use a timestamp method too, instead of doing your calculations based on setInterval.

What does this line mean in JavaScript? [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 6 years ago.
Improve this question
X=(x=== images.length-1) ? 0 : x+ 1;
Please help me I have no idea, and it's for a school task that I have to hand in.
I'm not sure why people are so opposed to just answering the question. It's a ternary operation. It's a shortcut for an if/else clause. For this particular operation,
Is x equivalent (===) to images.length-1? If so, set X to 0. Otherwise, set X to x + 1.
This pattern is likely used to endlessly iterate over an array (images). Once it reaches the end, it resets to the first element in the array.

Categories