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 8732403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:25:59+00:00 2026-06-13T09:25:59+00:00

check out my code It works but jsfiddle hates it for some reason. but

  • 0

check out my code

It works but jsfiddle hates it for some reason.
but when it’s ran in a browser i get NaN upon calculation

for some reason regardless of the parse it won’t return an integer to perform calculations on.

any one have an idea why?
also

// JavaScript Document
var payment

/* requirement #2* Each input (years, loan amount, interest rate)
   will have its own number pad for entry */
function getNum(id,span) {
    var a;
    a = parseInt(document.getElementById(id).value);
    document.getElementById(span).innerHTML += a;
}

function clear1(span) {
    document.getElementById(span).innerHTML = "";
}

/* requirment #7 Mortgage object with three variables:  years, amount, rate */
function Mortgage(years, amount, rate) {
    this.years = years;
    this.amount = amount;
    this.rate = rate;
    /*Requirment #8. Object must have an internal function that resets all
      values/variables to default and clears amounts displayed to user */
    this.clearAll = function() {
        document.getElementById(years).innerHTML = "";
        document.getElementById(amount).innerHTML = "";
        document.getElementById(rate).innerHTML = "";
    }
    /*gets the mortgage from spans*/                        
    this.getCalc = function() {
        /*Requirment # 9 Object must call at least 1 external function */
        get();
    }
}

function test() {          
    /*uses the params to call the spans id*/                     
    var c = new Mortgage('yInput','lInput','rInput');
    c.clearAll();
}

/* an external cunction to calculate mortgage*/
function get() {
    var m = new Mortgage(parseInt(document.getElementById('yInput').innerHTML),
                         parseInt(document.getElementById('lInput').innerHTML),
                         parseInt(document.getElementById('rInput').innerHTML)
    );

    /* this is NaN?*/
    document.write(m.years-m.rate);
}

function calculate() {
    var c = new Mortgage();
    c.getCalc();
}

http://jsfiddle.net/5qf7f/6/#run

  • 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-06-13T09:26:00+00:00Added an answer on June 13, 2026 at 9:26 am

    In the part:

    > /* this is NaN?*/
    > document.write(m.years-m.rate);
    

    Note that if the document has finished loading, a call to document.write will first call document.open, which clears the entire content of the document (including all scripts and the HTML element itself).

    http://jsfiddle.net/5qf7f/6/#run

    That “fiddle” doesn’t work at all for me. Better to reduce your code to an absolute minimum that displays the issue and post that. The exercise will likely lead you to your problem.

    It might help your investigation to know that parseInt('') returns NaN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I sometimes check out some previous version of the code to examine or test.
UPDATE: Turns out my code works. Browser was caching previous failed response. Thanks for
Please check out my following code... public enum LogType { Debug, Info, Warn, Error,
Check out this piece of JavaScript code: (function (w, d) { var loader =
Please check this code out it compiles and runs absolutely fine.. The question is
Could you please check out this piece of code: #include <vector> class A {
I use the svn-version of the gcc-4.7.0 to check out some C++11 features, e.g.
I'm trying to get started using git, but I'm having some troubles right away.
I have setup hudson to check out from my remote git repository but i
I went to the following site to check out some sweet custom fonts: http://www.fontspace.com/category/ninja

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.