hello I'm very new to javascript. I have only been programming iOS for a year. I am stuck on trying to increment a number in cloud code. I know I need to use Parse.Op.Increment() and amount(). but I must be doing something wrong I have gotten an error since I uploaded this line.
It DID look like this.(and worked)
var sum = Record.get("totalPunches");
Sum += request.params.punches;
Record.save("totalPunches", sum);
The line I am putting on cloud code looks like this.
Parse.Op.Increment("totalPunches", amount(request.params.punches));
any help on what I am doing wrong?
thank you
Related
This might be a dumb question but is it possible to run a for loop after a for loop is done executing?
I have a code but it doesn't seem to be running after the other for loop is done
var alphabet ='abcdefghijklmnopqrstuvwxyz';
var arr=[];
var sorting=[];
for(x=0;x<15;x++) {
arr.push(prompt("Enter your name in the format, First Name, Middle, Last:"));
var converter=arr[x].toLowerCase();
var name=converter;
document.write(name + "<br>");
}
for(y=0;y<15;y++) {
var name1=arr[y].toLowerCase();
var laster=name1.lastIndexOf(" ");
var sorterz=laster.substring(laster+1,laster+2);
var finder=alphabet.indexOf(sorterz);
sorting.push(finder.item)
document.write("ok");
}
Don't worry, we've all been there.
The answer to your question is yes, the for loop after that should run but why is it not running in your code?
After running your code here in codepen, I noticed that there is an error message in the console.
Uncaught TypeError: laster.substring is not a function at pen.js:0
If you were to do console.log(laster), you should see that it is a number.
To fix your error, just simply change laster.substring(laster+1,laster+2); to name1.substring(laster+1,laster+2); and your for loop should work accordingly.
Whenever you find that your javascript is not working, it is helpful to check the console of the web browser that you are using.
I've included the guides on how to use the consoles for popular browsers.
Chrome
Firefox
Edge
All the best to you in your journey in coding. We, programmers, are life long learners.
I'm trying to get this working off a branch of someone else's code, but wanted to take a hack at it, and so far, am not sure where the javascript is defined, etc. Not much knowledge here, but from what I'm understanding, this is suboptimal. I've tried a thing or two, but it breaks the whole page.
The TimeZone seems to display incorrectly: https://i.imgur.com/2OJrQuC.png
And the Javascript is here: https://github.com/mattgphoto/status/blob/master/script.js
It's something to do with formatDate, but am not sure what of the sections needs to be corrected, or if it's all of them. Would someone be able to help?
I think the following line in formatDate function is causing the problem.
return y.replace(/(y+)/g, function (v) {
return x.getFullYear().toString().slice(-v.length)
});
Try replacing that code with
return y;
Hope it works!
I'm trying to read some data from a google sheet and write them in a table in a google doc, using Google Apps Script.
It seems to me that I have successfully created a two dimensional array in the script, and populated it with the data from the google spreadsheet.
I also created a document with a paragraph. However, when I try to append the table I get the error message "Cannot convert Array to String[][]".
Below you find a snapshot (from the debugger) of the table (called "griglia") I'm trying to write, using the instruction
var grg = body.appendTable(griglia);
I also tried with a "test" table, as in the example provided here.
The test table won't give an error and appears in the document.
I cannot understand what is wrong with the first table (griglia).
The only thing that I notice is that the addresses in the second table are not increasing, while they are increasing in the first table. Is this relevant? Could I have made an error in creating the array?
I have a similar script, and it's working. It seems to me that I am creating the array and writing it in exactly the same way. In fact I copied most of the code from that script.
I did some research, but I could not find any clue.
I hope this is not too trivial, and that what I write is relevant.
Thanks
I found the answer.
The problem apparently was that I "allocated" 6 rows for the Array "griglia", but I actually "populated" only four of them (the ones shown in the figure above). The code for the allocation was the following
var griglia = new Array(6); // <== here is the culprit
for (j = 0; j < 4; j++){
griglia[j] = new Array(numD+2);
}
griglia[0][0]="Domanda";
griglia[1][0]="Risposta";
griglia[2][0]="Motivazione";
griglia[3][0]="Totale";
for (c = 1; c<numD+1; c++){
griglia[0][c]=c;
}
griglia[0][numD+1]='tot';
As soon as I corrected the first allocation, changing it to
var griglia = new Array(4);
The error disappeared.
I feel really stupid. The debugger didn't help much, though, because it showed that griglia had 4 rows and not 6, of which two are empty.
Anyway, my bad.
I do not know whether I should delete my silly question and feel stupid privately or leave it in StackOverflow and feel stupid publicly, but perhaps help other people who might face the same error.
So I am trying to convert a string to an integer in javascript and then comparing it to an integer variable I created. I have read many many things online but nothing worked so far. This is my code:
var followedUsers = $('.ProfileNav-item.ProfileNav-item--following.is-active').find('.ProfileNav-value').html();
so when I type followedUsers in console I get "1256". I tried parseInt as follows:
var x = parseInt(followedUsers,10);
But when I type x in console I get 2. Yes it is an integer but its not correct integer.
I also tried parseFloat. It gives the same result. This one didn't work either.
var x=parseInt(followedUsers.valueOf(),10);
I dont know if this is a thing but I was just messing around trying different things. I saw another guy's question. So I gave that a shot:
var x = +followedUsers
This one gave me a NaN.
var x = followedUsers*1
This one also gave me a NaN.
I tried converting my integer value to a string and comparing them that way but that doesn't gives me correct outputs. I am running out of ideas guys, am I missing something here? Changing a string to an integer shouldn't be this hard, right?
Perhaps followedUsers isn't what you think it is.
I made a simple example in JSBin, trying to simulate you problem and everything is working:
http://jsbin.com/huzegovaxa/edit?html,js,console,output
Try getting followedUsers with .val() insted of .html()
It turns out that the old browser in my university computer lab doesn't support parseInt or any other methods I mentioned above. It worked fine when I tried it on other computers. Although I believe this post will be useful for anybody looking for conversion in means of seeing all the methods in one place
Try
var x = parseInt(followedUsers);
I am currently having a problem with SSI's Custom Java Script Verification feature. I cannot make the program give me an error when a condition is not satisfied. I checked if javascript is enabled in my browser and it was. Also, I am sure to have it enabled in the survey. My code looks something like this:
var strErrorMessage= "";
var r1value = SSI_GetValue("q1_r1_c1");
var r2value = SSI_GetValue("q1_r2_c1");
if (r2value) < (r1value)
{strErrorMessage="error";}
However, when I put a smaller number in r2, it does not give an error and it continues on to the next question.
Any help is appreciated. Thanks in advance.
I think the last part should be
if(r2value < r1value)
Right now you have mismatched parentheses.