# Help needed in java script [Resolved]

Posted by Crniranjanraj under JavaScript on 11/22/2015 | Points: 10 | Views : 412 | Status : [Member] | Replies : 14
Write a JavaScript code to find the sum of N natural Numbers. (Use user-defined function)

#### Responses

Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50
 1 Try this (using for loop) ``` ``` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50
 0 Using While loop` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50
 0 Using the mathematical formula (this is the optimized one since this yields O(1) always)Sum of N Natural Numbers=(n*(n+1))/2 ` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50
 0 Using Map and Foreach function` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50
 0 Using Map and Reduce function` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50
 0 Using recursive function` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25
 0 Using Do..while loop` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25
 0 Using for..in loop` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25
 0 Using Map, Reduce and Arrow function` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25
 0 Using for loop in a reverse way` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25
 0 Using while loop in a reverse way` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Rajnilari2015 on: 11/22/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25
 0 Using do..while loop in a reverse way` ` -- Thanks & Regards, RNA TeamCrniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator
Posted by: Crniranjanraj on: 11/23/2015 [Member] Starter | Points: 25