node JS more than is incorrect [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 2 years ago.
Improve this question
Hi im pretty sure what im about to post might not be enough info (if so please let me know what more is needed). I am using node js and having a really weird error. Below is the code and output.
if (currentPrice > variableData[i].stopLossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}
Output:
if
92.7
is more than
93.62700000000001
This is consistently happening. I also made sure that both currentPrice and variableData[i].stopLossHard are numbers and not strings (I made sure in the code and in the output its the color of a number not a string)
Any ideas is highly appreciated.

The attribute you print is different than the one you check in the if statement:
(In the if stopLossHard has a capital L, stop-L-ossHard, what you print doesn't)
Try this:
if (currentPrice > variableData[i].stoplossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}

Related

How to remove underscores from a string array in typescript-angular project? [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 3 months ago.
Improve this question
i want to replace all the "_" occurrences from an array like this (TASK_1,TASK_2,TASK_3).
I receive this from the back-end and i cannot use the replace all because the project doesn't support es2021. I need to display the array like this (TASK 1,TASK 2, TASK 3).
I tried this method:
formatWithoutUnderScore(valueToFormat:any) {
return valueToFormat.map((value:any) => value.replace(/_/g, ' '));
}
and the used it:
this.formatWithoutUnderScore(this.totalTasks);
But it does nothing :(
Can someone help?
this.totalTasks = this.formatWithoutUnderScore(this.totalTasks);

Javascript string vs Variable value difference [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
I wanted to compare the value of variable which is getting the URL of current page with the hard coded string. Though the values are same I am getting false in the comparison. Not able to guess what is happening. Below is the code:
var loc = String('"' + window.URL + '"');
if("Here I am specifying entire URL manually exactly same which I am getting in loc"==String(loc))
{ console.log("true") }
else { console.log("false") }
This is pretty simple but I am missing something. Help needed. Thanks in advance.
You should use window.location.href instead . Since loc variable returns "function URL() { [native code] }" Hence the result is false.
window.location.href === "<Your string>"

Why are consts different to simple objects 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 3 years ago.
Improve this question
when i work in javascript canvas, when i created a basic object for aqngles like thius
const Angle =
{
Beginning:0*Math.PI,
OneQuarter:0.5*Math.PI,
TwoQuarter:1.0*Math.PI,
End:2*Math.Pi
}
and when i console log the outputs i get this:
0
NaN
but at the same time when i create unique consts for each like so:
const
startAngle = 0*Math.PI,
endAngle = 2*Math.PI;
and i console log it i get the response i want:
0
6.283185307179586
why does this happen? and how can i create a simple object with calculation and get a correct response? Thanks
Repl page:
https://repl.it/#Ballatoilet/EMDR
You have typo, it should be End:2*Math.PI and you have End:2*Math.Pi (small "i" letter).

javascript for loop does not work [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'm creating a site and i needed to do some js. I'm not that good with it but tought i would figer it out. Not. I created a for loop but it does not run.
function order(user,product){
var index;
for(var i = 0; i<users.lenght; i++){
if(user == users[i]){
index = i;
break;
}
}
var budget = budgets[index];
alert(budget);
}
the creation of the users and budgets arrays are done with php and after checking with alert() it was how it should be.
Can anyone help me please?
lenght is spelt length. The misspelt property does not exist, so it undefined, which is equivalent to 0.

JavaScript giving nonsense errors [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
So, me and a few friends are making a text adventure in JavaScript. in it, there is a possibility of the player using a heal spell, which runs the following code:
function heal() {
alert('You chant some ominous-sounding words, and your wounds heal');
alert('Hit points restored!');
hitPoints += 60;
blobsOfDoom -= 30;
burn();
MonsAtt();
Choose Spell();
}
Error Messages:
Firefox:
/*
Exception: SyntaxError: missing ; before statement
#Scratchpad/1:2703
*/
Chrome:
SyntaxError: Unexpected identifier.
Why is this error showing up? How do I fix it?
You cant have spaces in functions
Choose Spell();
Check your function declaration for ChooseSpell and any other occurances, and change them to a valid function name, like chooseSpell()

Categories