Why does JavaScript get this comparison wrong? [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 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.

Related

does anyone know how to correct this code [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 last year.
Improve this question
function tipCalculator(nonTipTotal)
{
var totalWithTip = nonTipTotal * 15;
console.log(`You should pay {totalWithTip} including tip`)
}
function tipCalculator();
It's supposed to print out the statement of the total with the tip included
Maybe this?
function tipCalculator(nonTipTotal) {
const totalWithTip = nonTipTotal * 1.15;
console.log(`You should pay ${totalWithTip} including tip`)
}
const billTotal = 25 // get your bill input somehow - depends how this runs
tipCalculator(billTotal);
You are missing the $ symbol before the opening curly bracket. It should be ${totalWithTip} instead of {totalWithTip}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Javascript backgroundColor works on some computers, not on others? [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 part of javascript code works on my home computer, but doesn't at work. Also, my colleague tested it and it doesn't work on her home computer?!
function klikNaX(x, y, z) {
var u = document.getElementById(z);
var u2;
u2 = u.style.backgroundColor;
document.getElementById("test").innerHTML = (z + " " + u2);
}
The problem seems to be with this part
u.style.backgroundColor;
Its not a problem of style.backgroundColor, instead please check if 'u' is a valid node and not undefined.
And try setting a color to u.style.backgroundColor = 'green'

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!

JQuery toFixed is not a function [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 this JavaScript code:
if($('#numlic').val() <= 10) {
$('#totalprice').text(23.10 * $('#numlic').val()).toFixed(2);
}
but it doesn't work and I get the "toFixed is not a function" error.
Can you help me with this?
Thanks in advance.
It's a simple typo:
if($('#numlic').val() <= 10) {
$('#totalprice').text((23.10 * $('#numlic').val()).toFixed(2));
}
The toFixed function is an extension of a Number. You're trying to set the element $('#totalprice') .toFixed(2), when you want to set the result of "23.10 * $('#numlic').val()".

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