Missing parenthesis before function parameters [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 3 months ago.
Improve this question
I'm trying to update some old code for a customer but I keep receiving missing ( before function parameters in my log files.
function gmtToFloat(tc) {
timecode = tc.toString();
var hhd = parseFloat(timecode.slice(-6, -3));
var mmd = parseFloat(timecode.slice(-2)) / 60;
return (hhd + mmd);
}
var diff =
gmtToFloat({Data.Session.utc}) - gmtToFloat({Data.Session.ctc});
diff;
What am I doing wrong?

Here:
function gmtToFloat(tc) {
timecode = tc.toString();
var hhd = parseFloat(timecode.slice(-6, -3));
var mmd = parseFloat(timecode.slice(-2)) / 60;
return hhd + mmd;
}
var diff = gmtToFloat(Data.Session.utc) - gmtToFloat(Data.Session.ctc);
diff;
You have to change gmtToFloat({ Data.Session.utc }) to gmtToFloat(Data.Session.utc)

Related

Split cookies from page [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 months ago.
Improve this question
I was doing some coding today, but I got an error:
Cannot read properties of undefined (reading 'split')
at getCookie ((index):38:49)
at (index):47:31
My code (begins at line 36, ends at 43):
var cookieArray = document.cookie.split(";");
for (var i = 0; i < cookieArray.length; i++) {
var cookiePair = cookieArray[1].split("=");
if(name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1])
}
}
Btw, I've read that you can only split a string, but this is a string right?
You should put i instead of 1:
for (var i = 0; i < cookieArray.length; i++) {
var cookiePair = cookieArray[i].split("=");
if(name== cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[i])
}
}
Because the first time it iterates the array cookieArray[1] my be undefind.

I am trying to concatenate the second parameter to the first in JS [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 11 months ago.
Improve this question
I'm pretty stuck, It should evaluate to ["present", "pretty", "precede"]
function addTooStart(x, y) {
let a = [];
let b = "";
for (let i in x) {
a = x.push(y);
a = x[b]
}
return a
}
let abc = addTooStart(["sent", "tty", "cede"], "pre");
console.log(abc)
I'm not sure what your a and b are attempting to do here. Some problems from your code:
x.push(y) adds the element y to the end of the array x, and then returns the new length of the array, so now a is a number.
x[b] will always be an invalid call, since b equals the empty string and is never changed, arrays are integer indexed.
The general approach here would be to loop through the array x, like you did, then for each element, set it equal to "y + current element". I have attached a working version below.
function addToStart(x,y){
for (let i = 0; i < x.length; i++) {
x[i] = y + x[i]
}
return x
}
addToStart([ "sent", "tty", "cede" ], "pre"); // -> [ 'present', 'pretty', 'precede' ]

Condensed some code, wondering if I may have added any unintended vulnerabilities or problems: [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 2 years ago.
Improve this question
I started with this code as part of a for loop:
var depthCat = "DMAD" + i.toString();
var tempDepth = document.getElementById("DMAD" + i.toString());
var depth = document.getElementById("DMAD" + i.toString()).value;
started thinking it was a little too verbose and slimmed it down to this:
var depth = document.getElementById("DMAD" + i.toString()).value;
my understanding of preventing injections and the like is limited, so I'm wondering if I've created any potential issues for myself?
Be careful, if no HTML element is found, then you will get an error
You should test if document.getElementById("DMAD" + i) is not null, or execute
var dmadElement = document.getElementById("DMAD" + i)
var depth = dmadElement ? dmadElement.value : null
or
var depth = null
try {
depth = document.getElementById("DMAD" + i).value
catch (e) {
// console.error(e)
}

How to take users input, modify it, then display it in JQuery? [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 am trying to make a unit converter, I will have the user enter a numeric value in a text box, select a unit type(lbs, g, oz etc...) from a select element, then do some simple multiplication to get the conversion, then finally, the part I am having trouble with, display the conversion result in a designated area. I can not get the text to change to the conversion result. I only have one conversion coded so far and that is pounds to grams, because I want to be able to display the text before I code the rest of them. Thank you and any input helps!
var main = function() {
var rslt = $('#result').val;
var num = $('#nmbr').val();
var inpt = $('#slct1').val();
var outpt = $('#slct2').val();
var bttn = $('.sbs');
$('.sbs').click(function(){
if(inpt == 'pounds'){
if(outpt == 'grams') {
var pGrams = num * 453.592;
$('#result').text(pGrams);
}
}
})
}
$(document).ready(main);
full code: https://jsfiddle.net/drzb6frk/
Try this javascript code:
var main = function() {
var bttn = $('.sbs');
$('.sbs').click(function(){
var rslt = $('#result').val;
var num = $('#nmbr').val();
var inpt = $('#slct1').val();
var outpt = $('#slct2').val();
if(inpt == 'pounds'){
if(outpt == 'grams') {
var pGrams = num * 453.592;
$('#result').text(pGrams);
}
}
})
}
$(document).ready(main);

Javascript/HTML error cannot find variable [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
Via onclick I am calling a function that does some calculations and then should be replacing some elements (h1) on the fly with the information calculated within the function.
I have this done the same exact way on several other places on my page, except this one seems to be giving me an error.
ReferenceError: Can't find variable: container2
I believe it might have something to do with the element's ID.
HTML:
<div id="macros">
<h4>Macronutrients recommended:</h4>
<h2>Protein: <span id="myprotein"></span></h2>
<h2>Fats: <span id="myfat"></span></h2>
<h2>Carbs: <span id="mycarb"></span></h2>
</div>
Javascript:
function calcmacros(bmr){
var bmrweightvalue = document.getElementsByName('bmr_weight_pounds')[0].value;
var bmrweight = parseInt(bmrweightvalue, 10);
var macro_p = (bmrweight*1);
//window.alert("protein is: " + macro_p);
var macro_f = (bmrweight*.25);
//window.alert("Fats are: " + macro_f);
var macro_c = (bmr - (macro_p * 4 + macro_f * 9))/4;
//window.alert("carbs are: " + macro_c);
var contianer2 = document.getElementById("myprotein");
container2.innerHTML = macro_p;
var contianer3 = document.getElementById("myfat");
container3.innerHTML = macro_f;
var contianer4 = document.getElementById("mycarb");
container4.innerHTML = macro_c;
}
Console:
ReferenceError: Can't find variable: container2
calcmacrosrdnSimulator.html:435
onclickrdnSimulator.html:101
Line 435 is
var contianer2 = document.getElementById("myprotein");
as stated above
You are defining the container variables as contianer but then referring to them are container.
Change the variables to container and then it should work correctly.
var container2 = document.getElementById("myprotein");
container2.innerHTML = macro_p;
var container3 = document.getElementById("myfat");
container3.innerHTML = macro_f;
var container4 = document.getElementById("mycarb");
container4.innerHTML = macro_c;
You are calling a variable that doest exist. Check your syntax...
for example...
var contianer2 = document.getElementById("myprotein");
container2.innerHTML = macro_p;

Categories

Resources