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 am using some simple javascript as below, but for some reasn the catParam is failing with error missing : after id. please help.
var catParam = "(id=cat00000)";
var inputParams = {serviceID:"getCategories",apiKey="asdfasfgx6",catCriterior:catParam};
Use
var catParam = "(id=cat00000)";
var inputParams = {serviceID:"getCategories",apiKey : "asdfasfgx6",catCriterior:catParam};
Instead - you are using an = instead of a : in your object literal. You assign properties of objects in literals using :.
Check out more info here.
Future reference
Try JsHint or JsLint to verify your code!
Also, if you have clean and organized code, it can make it easier to spot small errors like this, as well as improve the error messages you get (as your error will likely be on a shorter line). Using tools like JsBeautifier can get this done easily.
This would be your code after going through JS Beautifier:
var catParam = "(id=cat00000)";
var inputParams = {
serviceID: "getCategories",
apiKey: "asdfasfgx6",
catCriterior: catParam
};
Related
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 1 year ago.
Improve this question
I wanted to interpolate variables in strings in JS so I used ``(backticks) as shown here -
How To Interpolate Variables In String in JS
Then, I Wanted To put IF-Statements in jQuery Append So I got this -
IF Statements In jQuery Append
But When I use Both Together , Backticks Don't Output Text As Usual-
$("main").append(`Hello ${my_var}`+(second_var>1?"hi ":"bye")+`Bye ${my_var})`
This Results Only In "hi" , The Backticks Before And After The Ternary Operator Don't Output Anything.
HELP ??
You can do something like the below.
const my_var = "Name";
const seconde_var = 2;
console.log(`Hello ${my_var} ${seconde_var >1 ? "hi": "bye"} bye ${my_var}`);
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 1 year ago.
Improve this question
https://jsfiddle.net/c2o4j8fz/1/ - Where i get the code.
My code:
const chk = document.getElementById('chk');
const body = document.body;
$(function(){
chk.addEventListener('change', () => {
$('.body').toggleClass('dark');
localStorage.setItem("blockIsActive", $('.body').hasClass('dark'));
})
var blockIsActive = localStorage.getItem("blockIsActive")
if (blockIsActive == "true") {
$('.body').addClass('dark');
}
});
My code displays this error $ is not defined in the console, until i add jQuery, but in the jsfiddle example, it works in pure js. What am I doing wrong?
If you check the Resources tab of that fiddle, it actually says it includes jQuery:
Mind that $ isn't standard JavaScript, but a jQuery function/API to start with.
If you open Resources tab in the left menu you will see that jquery-2.1.4.min.js is included. So you have to include jQuery to get your code working.
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).
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 5 years ago.
Improve this question
I want to change all instances of the word "cão" on a page to read "gato" (following an older tutorial).
All instances of "cão" are inside a span and I´m trying to change them by using getElementsByTagName method.
Since there more than one, I cant use innerHTML to change the content so I´m using a for loop to cycle through all positions but I´m getting a sytax error after the increment i++. Why is that?
var elementoHeading = document.getElementById('heading');
elementoHeading.innerHTML = "Tudo sobre gatos";
var nomesTags = document.getElementsByTagName("span");
for (var i = 0, i < nomesTags.length, i++) {
nomesTags[i].innerHTML = "gato";
}
Use semicolons, not commas, in the for construct:
for (var i = 0; i < nomesTags.length; i++) {
^ ^
The reason the syntax error is after the increment is because the JS engine expects 3 statements inside of the for's brackets, but you only gave one (commas don't terminate the statement).
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
Why does 0.toFixed(2) print 0 instead of 0.00?
The correct answer:
Use a variable (noted by Rajesh in the comments)!
var num = 0
var fixedStr = num.toFixed(2);
This just looks better, is easier to understand and also safer, as it will throw errors to you if any occur.
Some Warning
Please note that some interpreters (just like the chrome console) do throw an error if you do 0.toFixed(2), as it is no valid JS to them. If you use a variable or brackets around the 0, it will be okay for them.
Another way for doing it
Also noted in the comments (by 4castle):
You can also use the following:
0..toFixed(2)
As the first dot will be interpreted as a decimal point, this will be okay for the interpreter and be parsed into "0.00".
But please do not use this, use a variable. It just looks horrible and not everyone understands what this should do (or why it magically works).
If you store 0 in a var, or if you use (0), it give 0.00.
(0).toFixed(2)
"0.00"
var x = 0;
x.toFixed(2)
"0.00"