Question

In: Computer Science

* Javascript * Describe an advantage or why someone would choose this loop type over another....

* Javascript *

  1. Describe an advantage or why someone would choose this loop type over another. Some things to consider and ask yourself:
    When would you use a for loop over a while loop? When would you use a while loop over a for loop? When would you use a do...while loop over a while loop?
  2. Give an example that fits the loop type's optimal use case (short answer, not code). Example scenario for a for loop (do not copy, be creative):
    Given an array of 100 numbers, iterate over each element/index and calculate the sum.

Solutions

Expert Solution

JavaScript code:-

<html>

<head>

</head>

<body>

<p>

<script>

var arr=[];

var sum=0;

for(var i=0;i<100;i++){

arr[i]=prompt('enter element'+(i+1));

arr[i]=parseInt(arr[i]);

sum=sum+arr[i];

}

window.alert('summation is='+sum);

</script>

</p>

</body>

</html>


Related Solutions

In this discussion topic, explain why a corporation would choose one type of interest over the...
In this discussion topic, explain why a corporation would choose one type of interest over the other when purchasing a stake in another corporation. Include in your discussion the advantages and disadvantages of each interest type for the acquiring and subsidiary corporation.
Choose a real-world example of someone you would describe as a great leader. Examples would include;...
Choose a real-world example of someone you would describe as a great leader. Examples would include; Steve Jobs, Colin Powell, Mahatma Gandhi, Elon Musk, Margaret Thatcher, etc. Prepare a 500-word essay describing their leadership successes as they relate to the "sources and types of power" discussed in chapter 8. Be sure to address their source of leader power (person vs position), type of leader power, and the overall impact of such power upon their leadership efforts. -Power of the Position...
Why would someone choose to do deep sequencing as compared to PCR amplification and sequencing of...
Why would someone choose to do deep sequencing as compared to PCR amplification and sequencing of short sequences?  What are some of the technology platforms used for deep sequencing?
Brokers With so much information available on the internet, why would someone choose to utilize a...
Brokers With so much information available on the internet, why would someone choose to utilize a broker, when investing?
1. a) Discuss the feedback loop for both hyperglycemia and hypoglycemia in someone with type 1...
1. a) Discuss the feedback loop for both hyperglycemia and hypoglycemia in someone with type 1 diabetes. Assume that the person does not have access to any medication. b) Explain why it is dangerous if diabetes goes untreated. 2. Hormonal contraceptives are prescribed for many biological females with abnormal menstrual cycles. Why is this done? Explain using an example of a hormonal contraceptive
Why would someone choose to use a prior month’s Excel file as a starting point rather...
Why would someone choose to use a prior month’s Excel file as a starting point rather than a template? What are some of the costs and benefits of using the prior month’s file instead of a template?
If you were working with someone with depression what therapy would you choose and why? What...
If you were working with someone with depression what therapy would you choose and why? What might be some social/cultural factors you may consider in your work if any?
Why would someone need to use a call option? Give a scenario of why someone would...
Why would someone need to use a call option? Give a scenario of why someone would want to use one. Also, pick a stock that has a call option written on it and describe how it would benefit someone who would purchase a call option. Showing math is required.
41. Explain how a PPD works. Include why someone from another country would have a positive...
41. Explain how a PPD works. Include why someone from another country would have a positive PPD test if they have never had the disease? How would they confirm or deny this? 42. Identify a disease that has a high incidence of asymptomatic carriers. Where does the organism hide in the body? How does this influence the spread of a disease? 43. Compare and contrast food poisoning by intoxication and infection by time of onset, treatment, and mode of action....
Read the below scenario. Choose the type of financial statementthat would best describe what is...
Read the below scenario. Choose the type of financial statement that would best describe what is occurring financially.You want to buy a home. The home is worth $100,000 and you have $25,000 in the bank. You go to the bank to get a $75,000 loan. The bank agrees and you receive $75,000 from the bank to buy the home.What financial statement would best describe this scenario?*Hint:- What is your equity (how much you had in the bank)?- What are your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT