Bitcoinani 70 #1 Posted November 11, 2017 Hello my pd frnds... I'm learning JavaScript and i've tried solving this geometric progression without success. The first and last terms are given which are a and b respectively according to the image attached. d is the common ratio and n which is the number of terms is not given. My solution prints way more than expected, my answer shouldn't be anywhere over the last term. This example should terminate at 27 . thereby adding only 3 items to the array. Solution attached as image http://postimg.org/image/1s7bg490zf/67f68eda/ Quote Share this post Link to post Share on other sites
iwant1btc 45 #2 Posted November 11, 2017 I would help u with heart, but i don't know so much nani 1 Bitcoinani reacted to this Quote Share this post Link to post Share on other sites
Bitcoinani 70 #3 Posted November 11, 2017 3 minutes ago, iwant1btc said: I would help u with heart, but i don't know so much nani Haha Its k... iwant1btc... i know that if you know you would have surely help me Quote Share this post Link to post Share on other sites
iwant1btc 45 #4 Posted November 11, 2017 I think u can get answer from google. Google can help your all question about JavaScript Quote Share this post Link to post Share on other sites
Noahbreezy 261 #5 Posted November 11, 2017 1 minute ago, iwant1btc said: I think u can get answer from google. Google can help your all question about JavaScript If he's not finding the answer himself he learned nothing. TIP: Cut the code in pieces, write down what the code does in every line. This can help you. 1 Bitcoinani reacted to this Quote Share this post Link to post Share on other sites
Bitcoinani 70 #6 Posted November 11, 2017 9 minutes ago, iwant1btc said: I think u can get answer from google. Google can help your all question about JavaScript i searched on google and didnt find so i asked here 6 minutes ago, Noahbreezy said: If he's not finding the answer himself he learned nothing. TIP: Cut the code in pieces, write down what the code does in every line. This can help you. okay i will try to execute each piece perfectly 2 Noahbreezy and iwant1btc reacted to this Quote Share this post Link to post Share on other sites
Serlite 576 #7 Posted November 11, 2017 @Bitcoinani Any luck? If you'd like some clues, I think I can nudge you in the right direction. Let me know if you've gotten any closer to a working solution. 1 Bitcoinani reacted to this Quote Share this post Link to post Share on other sites
Bitcoinani 70 #8 Posted November 11, 2017 1 minute ago, Serlite said: @Bitcoinani Any luck? If you'd like some clues, I think I can nudge you in the right direction. Let me know if you've gotten any closer to a working solution. No serlite, I was just waiting for you to get your eyes on my topic... i think now my problem will be solved Quote Share this post Link to post Share on other sites
Serlite 576 #9 Posted November 11, 2017 1 minute ago, Bitcoinani said: No serlite, I was just waiting for you to get your eyes on my topic... i think now my problem will be solved Hahaha, I'm not the only one who knows JavaScript here, you know. =P So, I'll start you off with some leading questions. Look through your code and see if you can find the problem I'm pointing at with them: Right now, you have a for loop nested inside a do-while loop. Your while condition is what checks whether you've reached the required term - when is it checked right now? How could you rearrange your code so it could be checked at a different time (possibly earlier)? Do you really need two loops? 1 Bitcoinani reacted to this Quote Share this post Link to post Share on other sites
Bitcoinani 70 #10 Posted November 11, 2017 3 minutes ago, Serlite said: Hahaha, I'm not the only one who knows JavaScript here, you know. =P So, I'll start you off with some leading questions. Look through your code and see if you can find the problem I'm pointing at with them: Right now, you have a for loop nested inside a do-while loop. Your while condition is what checks whether you've reached the required term - when is it checked right now? How could you rearrange your code so it could be checked at a different time (possibly earlier)? Do you really need two loops? Oh i understood now... so what if i do it with a single while loop? Quote Share this post Link to post Share on other sites
Serlite 576 #11 Posted November 11, 2017 2 minutes ago, Bitcoinani said: Oh i understood now... so what if i do it with a single while loop? I think you'd have a much easier time arranging your logic - that's the way I solved the problem! Quote Share this post Link to post Share on other sites
Bitcoinani 70 #12 Posted November 11, 2017 1 minute ago, Serlite said: I think you'd have a much easier time arranging your logic - that's the way I solved the problem! oh okay sir, wait i m doing it.. OMG serlite sir I solved it thank you so muchhh... function gp(a,b) { var arr = []; var d = 3; while (a<b){ arr.push(a); a = a*d; } console.log(arr); } Thank you your presence solved my problem Quote Share this post Link to post Share on other sites
Serlite 576 #13 Posted November 11, 2017 42 minutes ago, Bitcoinani said: oh okay sir, wait i m doing it.. OMG serlite sir I solved it thank you so muchhh... function gp(a,b) { var arr = []; var d = 3; while (a<b){ arr.push(a); a = a*d; } console.log(arr); } Thank you your presence solved my problem Well done! Glad you were able to get the solution in the end. Good luck on your continued learning of JavaScript! Quote Share this post Link to post Share on other sites
Bitcoinani 70 #14 Posted November 12, 2017 13 hours ago, Serlite said: Well done! Glad you were able to get the solution in the end. Good luck on your continued learning of JavaScript! Thank you sir... ? Quote Share this post Link to post Share on other sites
bruse 0 #15 Posted May 20, 2021 On 11/11/2017 at 20:03, Bitcoinani said: oh okay sir, wait i m doing it.. OMG serlite sir I solved it thank you so muchhh... function gp(a,b) { var arr = []; var d = 3; while (a<b){ arr.push(a); a = a*d; } console.log(arr); } Thank you your presence solved my problem You are smart Quote Share this post Link to post Share on other sites
Cmerald 1 #16 Posted April 4 I'm watching too see something interesting Quote Share this post Link to post Share on other sites