Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:10:59+00:00 2026-05-29T04:10:59+00:00

var number = 342345820139586830203845861938475676 var output = [] var sum = 0; while (number)

  • 0
var number = 342345820139586830203845861938475676
var output = []

var sum = 0;
while (number) {
    output.push(number % 10);
    number = Math.floor(number/10);
}

output = output.reverse();


function addTerms () {
    for (i = 0; i < output.length; i=i+2) {
    var term = Math.pow(output[i], output[i+1]);
    sum += term;

}
return sum;
}

document.write(output);
document.write("<br>");
document.write(addTerms());

I am trying to take that large number and split it into its digits. Then, find the sum of the the first digit raised to the power of the 2nd, 3rd digit raiseed to the 4th, 5th raised to the 6th and so on. for some reason, my array is returning weird digits, causing my sum to be off. the correct answer is 2517052. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:11:06+00:00Added an answer on May 29, 2026 at 4:11 am

    You’re running into precision issues within JavaScript. Just evaluate the current value of number before you start doing anything, and the results may surprise you:

    >>> var number = 342345820139586830203845861938475676; number;
    3.423458201395868e+35
    

    See also: What is JavaScript's highest integer value that a Number can go to without losing precision?

    To resolve your issue, I’d store your input number as an array (or maybe even a string), then pull the digits off of that.

    This will solve your calculation with the expected result of 2517052:

    var number = "342345820139586830203845861938475676";
    
    var sum = 0;
    for(var i=0; i<number.length; i=i+2){
      sum += Math.pow(number.charAt(i), number.charAt(i+1));
    }
    
    sum;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(function() { var number = document.getElementById(breuken); var i=0; for (i=1;i<=10;i++){ var fRandom = Math.floor(Math.random()*10);
I got this function in JS var number = Math.random() + ; var r
I have the following bit of code: protected function onEnterFrame(e:Event):void { var diff:Number; //
var x= 1; Number.prototype.test = function () { return this }; x.test() === x.test()
I have this (pseudocode): var a = Math.random(); // returns random number from 0
I have the following code: $(.zalen).change(function(){ var number = $(this).val(); $('.Zaal').load('zaal'+ number +'.html'); var
I cam across the following function in javascript: for (var number = 0; number
This is my Jquery script $(document).ready(function() { $('#form').submit(function() { var number = $('#number').val(); $.ajax({
$(function(){ $(#getitem).click(function(){ var txtval = $(#txt).val(); var number = ????? $('<input type=text name=txt'+number+' value='+txtval+'
function randomXToY(minVal,maxVal,floatVal) { var randVal = minVal+(Math.random()*(maxVal-minVal)); return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal); } Ball = (function()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.