Javascript Timer click button every 0.1 seconds [closed] - javascript

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 have a timer ( 15 ) and it count down till it reach 0 and then it repeat
their is a button that I want to click when the timer is less than 2
my code is :
setInterval(function(){
var x = document.getElementById('timer').innerHTML ;
function getSecondPart(str) {
return str.split('00<span>:</span>00<span>:</span>')[1];
}
if (getSecondPart(x) < 04) {
document.getElementById('bidButton').click();
}
} ,100);
but is return this error :
SyntaxError: expected expression, got ','
why ?

You're missing a bracket to close the function:
setInterval(function(){
if (getSecondPart(x) < 2) {
document.getElementById('bidButton').click();
}
} ,100);
Try to use more indentation and it will be clearer.

Related

Why doesn't this for loop work and my variable equals to zero? [closed]

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 2 years ago.
Improve this question
This is my first post on Stack Overflow, thanks in advance for answering me!
I need to count how many dots and exclamation marks there are in a single paragraph. I am using a for loop for this.
const storySigns = story.split('');
let puncCount = 0;
for (let i = 0; i < storySigns.length; i++)
{
if (i === '.' || i === '!') {
puncCount += 1;
}
};
Why does the output of puncCount equals 0?
I is a counter here its values is 0 then 1 then 2 then 3 until n
It will never be equal to '.' Or '!'

Why does JavaScript get this comparison wrong? [closed]

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 6 years ago.
Improve this question
This is happening on an angular application I'm building. If a user enters 80 into an HTML input, it always seems to get this comparison wrong.
var x = '80';
var y = 150.9800;
/* Returns incorrect answer */
if (parceFloat(x) < y) {
return true;
} else {
return false;
}
You need to use ParseFloat() not parceFloat() ...
parceFloat is not an existing function.
parceFloat() is not a function, the function is parseFloat()
A simple typo is all the error there is.

Map each value of an array to a given function to return a new array in JavaScript [closed]

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 6 years ago.
Improve this question
The code below throws the following exeption:
Uncaught TypeError: someFunction(...) is not a function
What is causing this exception to be thrown?
map = function (someList, someFunction){
var result =[];
for (x = 0; x < someList.length; x++ ){
result.push(someFunction(someList[x])());
}
return result;
};
map([1,2,3,4], function(num){
return num * 10;
});
The problem is in this line
result.push(someFunction(someList[x])());
^^
This extra parentheses are redundant. You are already calling the function someFunction by saying someFunction(someList[x]). By adding these extra parentheses, you are basically trying to call the return value of someFunction(someList[x]), which is a number here, not a function.

Dealing with javascript objects [closed]

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 6 years ago.
Improve this question
I have a function in javascript as so :
function player(){
var cards=[];
this.score=0;
var self=this;
this.addCard=addCard;
this.resetCards=resetCards;
function addCard(card){
cards.push(card);
this.score=+card.value;
}
function resetCards(){
cards=[];
score=0;
}
}
I user a constructor to call the function :
var player1=new player();
Then I call some of its enclosed functions like this
player1.addCard(someCardObject);//card someCardObject has .value say 5
player1.addCard(someCardObject);//card someCardObject has .value say 7
I expect player1.score to be 5+7=12 ,but it stays 7 .
Can anyone tell me what I am doing wrong here
You've got a simple error in addCard.
this.score=+card.value;
Should be
this.score += card.value;
In the first instance, you're setting this.score equal to card.value, while in the second one, you're adding card.value to it. Remember kids, order of operators matters!

How to create statement if contains "!" [closed]

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 6 years ago.
Improve this question
var input = message.content.toUpperCase();
if(input.indexOf("!")
{
bot.sendMessage(message, "!!!");
}
Help would be great, also earlier input was defined earlier
The String#indexOf method returns the index if found else returns -1. In your case .indexOf("!") return 0 and it's a false value and if statement never gets executed,so update your condition based on that.
if(input.indexOf("!") > -1)
or
if(input.indexOf("!") != -1)

Categories

Resources