Forum Replies Created
- AuthorPosts
- MD. Sakib KhanParticipant
A little Mistake in the conditions.
In the outer loop, the condition should be row <= 5
And in the inner loop, the condition should be col <= row
Rest of the code is okay.
Let me know if you understand the problem.MD. Sakib KhanParticipantYou are mentioning Question 3 in the title, but in the problem description, you are saying Question 5. Can you please tell me, In which one you are facing problem to solve?
MD. Sakib KhanParticipantProblem: 5 is kind of mixture of Exercise: Even Odd Numbers and Exercise: Sum of Numbers
For getting the sum of even numbers, your loop variable should start with 2. Because the first even number is two.
And every time when the loop ends, increase its value with 2 until its value reaches 100. (2, 4, 6, 8, 10, … ,100)
like that,for(let index = 2; index <= 100; index += 2) {
}
and For getting the sum of odd numbers, your loop variable needs to start with 1. like that,
for(let index = 1; index <= 100; index += 2) {}
Here are the solutions:
Even Sum: https://photos.app.goo.gl/3DSKfy1ckREbBfWQ7
Odd Sum: https://photos.app.goo.gl/WtgB8LWVwAUdXYoj9Let me know if it helps you.
MD. Sakib KhanParticipantHi Suresh,
Thank you for your proposal. I am currently working on that. On 23 September, I’ll publish lots of new videos and in there, I’ll show you where to submit the assignments and where you’ll get all the solutions.
Regarding the discussion, Many of my students are also telling me about a discussion group. I will share with you a slack/discord group where you can discuss problems with me or each other. (There will be an announcement on 23 September. Stay Tuned!)
Thank you
MD. Sakib KhanParticipantHi Sami,
For solving these kinds of pattern problems, you have to use Nested Loops.
For each row, you have to use a loop (Outer loop) and for each column, you have to use another nested loop (Inner Loop)And for placing the numbers/stars side by side in a row, follow these steps:
(I) Take a variable [In my code, it is Pattern]
(II) Every time when the loop starts, initialize the variable with an empty string (”)
(III) Add the numbers/stars with it.Here is my Solution:
Star Patterns: https://photos.app.goo.gl/y8fEooUXi1iZby1m8
Number Patterns: https://photos.app.goo.gl/uE2w2G8NudfEc7sK9As you can see, Each solution is kind of similar with slide differences. You just need to understand, Is the loop variable incremental or decremental. That’s it.
Let me know brother if you understand the way to solve these kinds of problems.
Thank you.
MD. Sakib KhanParticipantHi Mustakim,
To solve this problem, You need to follow these steps:
i) Take a Sum Variable
ii) Add the last digit of the number (If a number is divided by 10, its remainder (ভাগশেষ) is the last digit of that number)
iii) Remove the last digit (Just divide it by 10)
iv) Repeat from step (ii) until the number is zero.
v) You will get the sum.Here is the solution: https://photos.app.goo.gl/iGEvFYNyXav2LTHz9
Let me know if it helps you.
Thanks.MD. Sakib KhanParticipantHi Sami,
Yes, you can solve this problem using Ternary Operators.
Here is the solution: https://photos.app.goo.gl/C31TQMGjr8YP9MTPA
Logic is same as before. If you don’t understand, let me know.
But we shouldn’t do like that. This is pretty ugly and not understandable code.
When the problem needs only if…else to solve,then we should use ternary operators.
If number of conditions is greater than two, then we should use if..else if.. elseMD. Sakib KhanParticipantIs your question, How can we copy a line of code, and paste it multiple times?
you can just go to a line and press Ctrl+C (It will copy the whole line) and then press Ctrl+V multiple times. It will paste the codes in new lines.If you are searching something like that, if you write cons and then VS Code will auto-complete your code/give you some suggestions, for that you can install a extension (Just like you’ve installed Live Server), It is JavaScript (ES6) Code Snippets
And in VS Code, You can select all the occurrences of a portion of code using Ctrl+D
MD. Sakib KhanParticipantHi Suresh brother,
Welcome to this course and I am very very happy to see your progress.Here is the keyboard shortcuts:
Ctrl + X for CUT
Ctrl + C for COPY
Ctrl + V for PASTE
Ctrl + Z for UNDOBy these shortcuts, you can also cut,copy,paste the whole line of the code in VS Code.
Let me know if it works for you - AuthorPosts