Missing ) after formal parameters. (line 1, file "Code") - google-apps-script

I am trying to make a count down clock using a user input to start it on Google Apps Script (Which uses JavaScript). And I'm getting the error (I think it is Syntax):
"Missing ) after formal parameters. (line 1, file "Code")"
Here is my code:
function COUNTD(Browser.inputBox(prompt))
{
var clock = Browser.inputBox("Intiate countdown sequence?");
if(clock == "yes")
{
return("T - 30 minutes and counting...");
}
if(count == "abort")
{
return("Countdown aborted")
}
}
I know there are multiple variations of this question, but I couldn't user the answers given for those and apply them to mine.
Am I just being really stupid?

I think what you need here is something like this:
function COUNTD(bInputBox)
{
var clock = bInputBox("Intiate countdown sequence?");
if(clock == "yes")
{
return("T - 30 minutes and counting...");
}
if(count == "abort")
{
return("Countdown aborted")
}
}
COUNTD(Browser.inputBox);

Related

My code in Apps script is taking too much time to execute

If the user sets value of C2 as Message Finder then my cell should go to c77. I have such say 9-10 cases. I have added 3 cases in the code.
But, it is taking too long and my sheet shows "Running script for more than 8-10 seconds.
My aim is to reduce it to just 1-2 seconds or at least better than current situation
function getTool()
{
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Course");
if(sheet.getRange("c2").getValue() == "Message Finder")
{
sheet.setActiveCell("Course!T95");
}
else if(sheet.getRange("c2").getValue() == "Fee Finder")
{
sheet.setActiveCell("Course!U39");
}
else if(sheet.getRange("c2").getValue() == "Fee Message")
{
sheet.setActiveCell("Course!N39");
}
}
Please help. Thanks
Still see no big problem with your code.
Though probably you can speed up the code this way:
function getTool() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Course');
var cell = sheet.getRange('c2').getValue();
if (cell == 'Message Finder') { sheet.getRange('t95').activate(); return }
if (cell == 'Fee Finder') { sheet.getRange('u39').activate(); return }
if (cell == 'Fee Message') { sheet.getRange('n39').activate(); return }
}

Sorting an array of objects using a well known dynamicSort function, but getting this error: "Comparison method violates its general contract"

I am generating an array of calendar events and then (using code I got from user 'Cooper') I am deduplicating the list to create a new array: dedList
// This code creates a deduplicated array (dedList) from my array 'events' (parts of this code are from Cooper on StackOverflow... and I don't really understand it all)
var dedList=[];
var obj={eA:[]};
for(var i=0;i<events.length;i++) {
var key=events[i].getTitle() + events[i].getDescription();
if(!obj.hasOwnProperty(key)) {
obj[key]={
title: events[i].getTitle(),
description: events[i].getDescription(),
guest_list: events[i].getGuestList(),
guests: events[i].getGuestList().length,
start: events[i].getStartTime(),
end: events[i].getEndTime(),
recurs: events[i].isRecurringEvent(),
duration: "",
creator: events[i].getCreators(),
color: events[i].getColor() ,
copies: 0,
category: "",
};
obj.eA.push(key);
}else{
obj[key].copies+=1; //count the copies
}
}
for(var i=0;i<obj.eA.length;i++) {
dedList.push(obj[obj.eA[i]]);
}
This is working perfectly, but I'm using some well shared code to sort dedList by "category" and it's generating error I've never seen before: "Comparison method violates its general contract." Here's the line causing the error, followed by the function I am using:
dedList.sort(dynamicSort("category")); // this line generates the error
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
Any suggestions? I'm pretty new to google scripting so I don't completely understand how the dynamicSort function works, and that is making it hard for me to debug the error. Thanks!
MCVE:
function sortTest() {
var arr = [];
for (i = 0; i < 50; ++i) {
arr.push({ a: '' }, {}, { a: {} });
}
Logger.log(arr.sort(dynamicSort('a')));
}
function dynamicSort(property) {
var sortOrder = 1;
return function (a,b) {
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
Engine: Rhino (Old)
Error:
Comparison method violates its general contract
Thanks for all the help. The code I posted works fine; the problem was that I had another function that was changing some category values to "undefined". I fixed this and my problem went away, and my array is sorting perfectly now.
I was going to delete this post, but the MCVE added by #TheMaster may still be relevant? I'll leave it for now.
Have you tried dedList.sort(function(a,b){return a.category-b.category});
or vice-versa dedList.sort(function(a,b){return b.category-a.category});
also you should remove the trailing comma from this line category: "",
If that doesn't work I'd consider making life easier by initializing all of the categories with "AAAAA";

Google sheets script always returning same respone

Still quite new to this.
I have written a function:
function maxHousing(actualCost,allowedCost){
if (actualCost == ""){
return "";
}
if (parseInt(actualCost) <= parseInt(allowedCost)){
return actualCost;
}
else{
return allowedCost;
}
}
I then have a field in my sheet with the formula:
=ARRAYFORMULA(
if(
row(Parents!A:A)=1,
"Allowed Housing",
maxHousing(Parents!D1:D,Allowances!B6)
)
)
This function always returns allowedCost, no matter what I make actualCost.
I'm clearly doing something really obviously wrong here!

Google spreadsheets custom function code not working: =RootDomain

Hi I am trying to program a Google spreadsheets custom function. It receives a range and spits out the clean rootdomain. I just ran into an "too many executions" - I have to run this on my whole sheet. So I added a range.
Now the feedback is "internal error function" ....
Help appreciated .... this must be possible!
/**
* Generates clean root domains
*
* #param {input} input The value to change to a root domain.
* #return The clean root domain.
* #RootDomain
*/
function RootDomain(input) {
if (input == null) return '';
if (input.map) { // Test whether input is an array.
return input.map(RootDomain); // Recurse over array if so.
} else {
if (input = '') return '';
regex = new RegExp(/((www)\.)?.*(\w+)\.([\w\.]{2,6})/);
return regex.exec(input)[0].replace(/^http(s)?:\/\//i, "").replace(/^www\./i, "").replace(/\/.*$/, "");
}
}
Do this instead:
function RootDomain(input) {
if (input == null || input === '') {
return '';
} else if (input.map) { // Test whether input is an array.
return input.map(RootDomain); // Recurse over array if so.
}
var regex = new RegExp(/((www)\.)?.*(\w+)\.([\w\.]{2,6})/);
return regex.exec(input)[0].replace(/^http(s)?:\/\//i, "").replace(/^www\./i, "").replace(/\/.*$/, "");
}

How do you create an if statement to check if many objects style == dispaly:none?

I'm making a memory-match game in which you flip two cards over in order to get them to match.
I'm doing it with simple if statements as shown below:
if(click == 2) //denotes two cards being clicked
{
if(flippedArray[1].src === flippedArray[0].src) // if click 1 == click 2 then refer to function 'delayMatch' which sets click 1 and 2 cards to not be displayed
{
window.setTimeout(function() { delayMatch() }, 500);
console.log("EQUAL");
score = +25000;
}
else
{
window.setTimeout(function() { delayNoMatch() }, 500); // if click 1 != click 2 then display card.png
console.log("NOT EQUAL");
score = -1999;
}
function delayMatch() //function for matching pairs
{
flippedArray[0].style = "display:none;";
flippedArray[1].style = "display:none;";
}
function delayNoMatch() //function for non-matching pairs
{
flippedArray[0].src = "card.png";
flippedArray[1].src = "card.png";
}
click = 0; // when clicked two cards set click back to zero
}
As you can see if two cards match they're set to display:none. What I'm trying to do is link to an "end game" html page once all 36 divs are set to display: none or I guess once the function delayMatch() has been called 18 times.
I'm completely at a loss as how I can do this.
my goal is something like this:
flippedArray[0] and flippedArray[1] is just a temporary array to check if the two cards currently in play are a match or not.
I was thinking something like:
endGameCounter =0;
endGameCounter++; //in the matching if-statement
then if(endGameCounter == 18)
{
location.href='link here'
}
You can use one variable for count inside the page.
If you are doing it in JSP, JSTL can help you here.
use to set a variable and just check the value time to time.
c:set var="COUNT" value="SOMETHING"/>
Try
function GameIsOver(){
for (var i = 0; i < allCards.length; i++) {
if(allCards[i].style.display === 'none')return false;
}
return true;
}