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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:54:51+00:00 2026-06-03T14:54:51+00:00

I’m new to JavaScript and trying to learn more about what it can do

  • 0

I’m new to JavaScript and trying to learn more about what it can do and how to use it.

is it possible to return multiple results as a result of a calculation?

I am working on a calculator for a class project. What I would like it to do is return 3 values on my page:

Interest rate

total amount borrowed and
monthly repayment

So far I have managed to get it to display monthly repayment in a div on the page, but I would like to be able to show all 3 on the page as a result of the one calculation.

Is this possible?

Here is what I have come up with so far:
HTML:
<p><input type="button" onclick="main();" value="Calculate"></p>

JavaScript:

function main()
{

var userInput1 = 0;
var userInput2 = 0;
var displayResult;


userInput1 = document.getElementById("loan_amount").value;
userInput1 = parseFloat(userInput1);
userInput2 = document.getElementById("loan_term").value;
userInput2 = parseFloat(userInput2);

displayResult = calcLoan(userInput1,userInput2);
document.getElementById("Result1").innerHTML=displayResult;

}

function calcLoan(userInput1,userInput2)
{
var interest =0;


    if (userInput1 <1000)
    {
    alert("Please enter a value above £1000")
    }
    else if (userInput1 <= 10000)
    {
    interest = 4.25 + 5.5;
    }
    else if (userInput1 <= 50000)
    {
    interest = 4.25 + 4.5;
    }
    else if (userInput1 <= 100000)
    {
    interest = 4.25 + 3.5;
    }
    else 
    {
    interest = 4.25 + 2.5;
    }


var totalLoan = 0;  


    totalLoan = userInput1 +(userInput1*(interest/100))*userInput2; 

var monthlyRepayment = 0;
var monthly;


    monthlyRepayment = totalLoan/(userInput2*12);
    monthly=monthlyRepayment.toFixed(2);


    alert("Interest Rate = " + interest + "%" +" "+"Total Loan amount = " + "£"+ totalLoan +" "+ "Your monthly repayment is = " + " " + "£"+ monthly);

return monthly; 

}

If anyone can point me in the right direction, it would be great!

  • 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-03T14:54:52+00:00Added an answer on June 3, 2026 at 2:54 pm

    You can create variables with multiple custom fields and pass them between functions. So, your functions should look like this:

    function main()
    {
        ...
    
        displayResult = calcLoan(userInput1,userInput2);
        document.getElementById("Result1").innerHTML = displayResult.interest;
        document.getElementById("Result2").innerHTML = displayResult.totalLoan;
        document.getElementById("Result3").innerHTML = displayResult.monthly;
    }
    
    function calcLoan(userInput1,userInput2)
    {
        ...
    
        alert("Interest Rate = " + interest + "%" +" "+"Total Loan amount = " + "£"+ totalLoan +" "+ "Your monthly repayment is = " + " " + "£"+ monthly);
    
        var result;
        result.interest = interest;
        result.totalLoan = totalLoan;
        result.monthly = monthly;
    
        return result; 
    }
    

    And don’t forget to add div elements with IDs Result1, Result2 and Result3.

    <div id="Result1"></div>
    <div id="Result2"></div>
    <div id="Result3"></div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small

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.