Missing ) after arguement list. (line 6 file "code") [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 8 years ago.
Improve this question
I'm new to coding and a got this pre set code to use within a spreadsheet for a google awesome table, and I keep getting this error.
Missing ) after argument list. (line 6, file "Code)
Here is my code:
var formURL = 'https://docs.google.com/a/waitrose.co.uk/forms/d/11-z44oW1ixP1tShkwjrBpa0DptOA2IinU5MCCkUvf0o/viewform';
var sheetName = 'Form responses 1';
var columnIndex = 5;
function getEditResponseUrls(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Form responses 1);
var data = sheet.getDataRange().getValues();
var form = FormApp.openByUrl(formURL);
for(var i = 2; i < data.length; i++) {
if(data[i][0] != '' && (data[i][columnIndex-1] == '' || !data[i][columnIndex-1])) {
var timestamp = data[i][0];
var formSubmitted = form.getResponses(timestamp);
if(formSubmitted.length < 1) continue;
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
sheet.getRange(i+1, columnIndex).setValue('<div style="width:100px">Edit entry</div>');
}
}
}

Looks like you are missing a pair of quotes on line 6:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Form responses 1);
should be
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form responses 1");

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.

Why some parts of this code are red in VS 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 3 months ago.
Improve this question
I just started to learn JavaScript. I have this script which should generate composite numbers in my separate HTML file, but I don't really understand why some parts are highlighted red when I moved script to .js file.
So my question is why there are some parts that are highlighted and how I'm suppose to write it correctly? I need to use strict in this script. I know that when using strict mode I need to declare variables, objects etc.
since you are working in a javascript file.
remove the script tags
you only need script tags in other file types like html etc
function checkComposite(num) {
var arr = [];
if( var num == 1 ) {
return false;
}
else if ( var num == 2) {
return false;
}
for (var x = 2; x < num; x++) {
if(num % x == 0) {
return true;
}
}
return false;
}
function compositeNumbers() {
num = Number(document.getElementsById('number').value);
for(var j = 1; j < num; j++) {
if(checkComposite(j)) {
arr.push(j);
}
}
document.getElementsById('result').innerHTML = arr;
}

Codes block has an syntax error [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
For some reason this code block is giving an error and i can't figure out what is the matter with it. Any help is appreciated.
function Submit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = e.getActiveSheet();
var range = e.getActiveRange();
var cell = range.getActiveCell();
var cellValue = ss.getActiveCell(9,17);
if( cellValue == <0 ){
var report = s.getDataRange("A101:Q106");
var numColumns = s.getLastColumn();
var targetsheet = ss.getSheetByName("Report");
var date = s.getSheetName();
var target = targetsheet.getRange(targetsheet.getLastColumn() + 1 , 1);
e.getRange(report).copyTo(target);
}
}
This is the line that is causing the syntax error:
if( cellValue == <0 ){
If you just want to know if cellValue is equal to 0, then you should change it to:
if( cellValue == 0 ){
If you're trying to see if cellValue is less than 0, then the proper way is:
if( cellValue < 0 ){
See http://devdocs.io/javascript/operators/comparison_operators for more information.

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 - Passing from a DOM element to array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Hello and thank you for your time.
Here is the code :
<script>
var names = document.getElementsByClassName('xx');
var ar = [];
for (var i = 0, c = names.length ; i < c ; i++) {
ar[i] = names[i].innerHTML;
alert(ar[i]);// the results are : undefined
}
</script>`
I've tried to use the method tostring, or to push the results into the array but without success.
Thanks
Your main issue seems to be fixed. Make sure the DOM has been loaded before you try to run your code, and there is no need for two variables in your loop. Simplify it like below:
window.onload = function () {
var names = document.getElementsByClassName('xx');
var ar = [];
for (var i = 0 ; i < names.length ; i++) {
ar[i] = names[i].innerHTML;
alert(ar[i]);
}
};
Fiddle
ar.length equals 0, because you just declare the array, but dont put anything into it. I think what you wanted to do is the following:
var names = document.getElementsByClassName('xx');
var ar = [];
for (var i = 0 ; i < names.length ; i++) {
ar[i] = names[i].innerHTML;
alert(ar[i]);
}

Categories

Resources