polaryeti Posted December 6, 2022 Share Posted December 6, 2022 I want this pattern, what's the logic behind this one? There are lots of blogs online that show code but not teach technique. Share any blogs that you know that teach the logic behind it as well. At i=1, j=5 should be printed as star, rest as white spaces At i=2, j=4,6… At i=3, j=3,5,7…. At i=4,j=2,4,6,8… At i=5, j=1,3,5,7,9… How do I convert this into logic? Quote Link to comment https://forums.phpfreaks.com/topic/315617-how-to-print-this-pyramid-pattern/ Share on other sites More sharing options...
requinix Posted December 6, 2022 Share Posted December 6, 2022 What code have you tried so far and what did it output? Quote Link to comment https://forums.phpfreaks.com/topic/315617-how-to-print-this-pyramid-pattern/#findComment-1603293 Share on other sites More sharing options...
Solution polaryeti Posted December 6, 2022 Author Solution Share Posted December 6, 2022 for (i = 1; i <= 5; i++) { for (space = 1; space <= 5 - i; space++) { document.write("0"); } for (j = 1; j <= i; j++) { document.write("X0"); } document.write("<br>"); } I got help from tutorial video to solve this. Quote Link to comment https://forums.phpfreaks.com/topic/315617-how-to-print-this-pyramid-pattern/#findComment-1603294 Share on other sites More sharing options...
requinix Posted December 6, 2022 Share Posted December 6, 2022 That's functional but not quite what modern Javascript code is supposed to look like. Want to spend some time improving it with our help? 1 Quote Link to comment https://forums.phpfreaks.com/topic/315617-how-to-print-this-pyramid-pattern/#findComment-1603296 Share on other sites More sharing options...
Barand Posted December 6, 2022 Share Posted December 6, 2022 7 hours ago, polaryeti said: How do I convert this into logic? If there are N rows, each row r comprises (N-r) spaces followed by "* " (star-space) repeated r times. Quote Link to comment https://forums.phpfreaks.com/topic/315617-how-to-print-this-pyramid-pattern/#findComment-1603297 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.