How to generate number pattern inside loop?How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?JavaScript closure inside loops – simple practical exampleGenerating random whole numbers in JavaScript in a specific range?How to check whether a string contains a substring in JavaScript?Loop through an array in JavaScriptGenerate random number between two numbers in JavaScriptHow do I remove a particular element from an array in JavaScript?
Why Shazam when there is already Superman?
Not using 's' for he/she/it
Count the occurrence of each unique word in the file
Is it safe to use olive oil to clean the ear wax?
Is it possible to have a strip of cold climate in the middle of a planet?
Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?
How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?
Is it better practice to read straight from sheet music rather than memorize it?
Why electric field inside a cavity of a non-conducting sphere not zero?
How could a planet have erratic days?
What if a revenant (monster) gains fire resistance?
copy and scale one figure (wheel)
If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?
Aragorn's "guise" in the Orthanc Stone
If infinitesimal transformations commute why dont the generators of the Lorentz group commute?
250 Floor Tower
Energy measurement from position eigenstate
Redundant comparison & "if" before assignment
Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed
Travelling outside the UK without a passport
"Spoil" vs "Ruin"
Is there a single word describing earning money through any means?
The IT department bottlenecks progress. How should I handle this?
Does a 'pending' US visa application constitute a denial?
How to generate number pattern inside loop?
How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?JavaScript closure inside loops – simple practical exampleGenerating random whole numbers in JavaScript in a specific range?How to check whether a string contains a substring in JavaScript?Loop through an array in JavaScriptGenerate random number between two numbers in JavaScriptHow do I remove a particular element from an array in JavaScript?
I have the following code:
for ( let i = 1; i <= 12; i++ )
console.log(i % 4);
It generates the output:
1
2
3
0
1
2
3
0
1
2
3
0
I'm trying to change the pattern (i % 4
) so it gives me the following sequence instead:
1
1
1
1
2
2
2
2
3
3
3
3
I don't want to use a variable for it, just change the pattern inside the console.log
to a good one that doesn't rely on for example multiple tenary operators.
It should keep increasing 1 every 4 iterations and work for more than 12 iterations.
javascript for-loop
add a comment |
I have the following code:
for ( let i = 1; i <= 12; i++ )
console.log(i % 4);
It generates the output:
1
2
3
0
1
2
3
0
1
2
3
0
I'm trying to change the pattern (i % 4
) so it gives me the following sequence instead:
1
1
1
1
2
2
2
2
3
3
3
3
I don't want to use a variable for it, just change the pattern inside the console.log
to a good one that doesn't rely on for example multiple tenary operators.
It should keep increasing 1 every 4 iterations and work for more than 12 iterations.
javascript for-loop
add a comment |
I have the following code:
for ( let i = 1; i <= 12; i++ )
console.log(i % 4);
It generates the output:
1
2
3
0
1
2
3
0
1
2
3
0
I'm trying to change the pattern (i % 4
) so it gives me the following sequence instead:
1
1
1
1
2
2
2
2
3
3
3
3
I don't want to use a variable for it, just change the pattern inside the console.log
to a good one that doesn't rely on for example multiple tenary operators.
It should keep increasing 1 every 4 iterations and work for more than 12 iterations.
javascript for-loop
I have the following code:
for ( let i = 1; i <= 12; i++ )
console.log(i % 4);
It generates the output:
1
2
3
0
1
2
3
0
1
2
3
0
I'm trying to change the pattern (i % 4
) so it gives me the following sequence instead:
1
1
1
1
2
2
2
2
3
3
3
3
I don't want to use a variable for it, just change the pattern inside the console.log
to a good one that doesn't rely on for example multiple tenary operators.
It should keep increasing 1 every 4 iterations and work for more than 12 iterations.
for ( let i = 1; i <= 12; i++ )
console.log(i % 4);
for ( let i = 1; i <= 12; i++ )
console.log(i % 4);
javascript for-loop
javascript for-loop
edited 2 days ago
user7393973
asked 2 days ago
user7393973user7393973
979532
979532
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You could divide the value by 4
and take the value with Math.ceil
for the next integer number.
for ( let i = 1; i <= 12; i++ )
console.log(Math.ceil(i / 4));
Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.
– user7393973
2 days ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281317%2fhow-to-generate-number-pattern-inside-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could divide the value by 4
and take the value with Math.ceil
for the next integer number.
for ( let i = 1; i <= 12; i++ )
console.log(Math.ceil(i / 4));
Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.
– user7393973
2 days ago
add a comment |
You could divide the value by 4
and take the value with Math.ceil
for the next integer number.
for ( let i = 1; i <= 12; i++ )
console.log(Math.ceil(i / 4));
Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.
– user7393973
2 days ago
add a comment |
You could divide the value by 4
and take the value with Math.ceil
for the next integer number.
for ( let i = 1; i <= 12; i++ )
console.log(Math.ceil(i / 4));
You could divide the value by 4
and take the value with Math.ceil
for the next integer number.
for ( let i = 1; i <= 12; i++ )
console.log(Math.ceil(i / 4));
for ( let i = 1; i <= 12; i++ )
console.log(Math.ceil(i / 4));
for ( let i = 1; i <= 12; i++ )
console.log(Math.ceil(i / 4));
answered 2 days ago
Nina ScholzNina Scholz
193k15105177
193k15105177
Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.
– user7393973
2 days ago
add a comment |
Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.
– user7393973
2 days ago
Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.
– user7393973
2 days ago
Thanks. I could not remember at all what was it to make such sequence and was complicated to search it aswell.
– user7393973
2 days ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281317%2fhow-to-generate-number-pattern-inside-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown