1. - When I use console.gotoxy(0,24); it takes me to line 22, not 24. Is this a normal thing +/- a few lines, or is it supposed to be dead accurate.
2. - what are the { and } used for. As far as I can tell be reading up, they are only deed for condition statements. Just trying to understand.
Re: 2 questions
By: DesotoFireflite to All on Fri Apr 08 2022 05:45 pm
1. - When I use console.gotoxy(0,24); it takes me to line 22, not
24. Is this a normal thing +/- a few lines, or is it supposed to be
dead accurate.
console.gotoxy() should be exactly accurate. Note that the X and Y cursor coordinates are 1-based. You may be off by 1.
2. - what are the { and } used for. As far as I can tell be reading
up, they are only deed for condition statements. Just trying to
understand.
There are several things { and } can be used for.
1. To surround blocks of code that contain more than one statement, such as: if (x === 1)
{
console.print("x is 1");
console.crlf();
console.pause();
}
2. When defining functions:
function printNumber(num)
{
console.print(num);
}
3. When defining objects:
var anObj = {
aNum: 1,
aString: "String"
};
There may be more cases I'm not thinking of.
1. - When I use console.gotoxy(0,24); it takes me to line 22, not 24. Is this a normal thing +/- a few lines, or is it supposed to be dead accurate.
2. - what are the { and } used for. As far as I can tell be reading up, they are only deed for condition statements. Just trying to understand.
Re: 2 questions
By: DesotoFireflite to All on Fri Apr 08 2022 17:45:57
1. - When I use console.gotoxy(0,24); it takes me to line 22, not
24. Is this a normal thing +/- a few lines, or is it supposed to be
dead accurate.
I believe these coordinates are 1-based, so the top left cell is 1,1. Even so I would only expect you to end up one row above where you intended. Not sure what's up with that.
FYI if your intention is to move to the first column of the last line in the terminal, I would recommend:
console.gotoxy(1, console.screen_rows);
This will get you there no matter what the dimensions of the terminal are. (There is also a 'screen_columns' property.)
2. - what are the { and } used for. As far as I can tell be reading
up, they are only deed for condition statements. Just trying to
understand.
Curly braces do a few different things in JS, but mostly they're creating a 'block' to group several statements together. If your 'if' statement only needs to do one thing, then you don't need them:
Sysop: | Gary Ailes |
---|---|
Location: | Pittsburgh, PA |
Users: | 132 |
Nodes: | 5 (0 / 5) |
Uptime: | 109:47:44 |
Calls: | 733 |
Files: | 2,171 |
Messages: | 81,483 |