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

  • Home
  • SEARCH
  • 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 8895985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:55:34+00:00 2026-06-14T23:55:34+00:00

I am trying to write a short piece of html code that, given two

  • 0

I am trying to write a short piece of html code that, given two initial amounts, attempts to find the number greater than or equal to the first that wholly divides the second given amount. The code tries to divide the numbers, and if it is unsuccessful, adds 1 to the first number and tries to divide again, etc…

I want the code to return the value that does wholly divide the second number AND the answer to the division (with some plain text appearing around it).

Added to this, or at least I’d like there to be, is that upon clicking one of 5 different buttons a multiplication operation is performed on the first given number, it is rounded up to the nearest whole number, and THEN the function attempts to divide this into the second given number.

It’s difficult to explain exactly what I want without showing you the code I have so far, so here it is:


<html>

<head>

<b>Rounded Commodity Pricing:</b><br>

</head>

<script language="Javascript">

var currency;

function setCurrency(val) {
 var currency = val;
}

function finddivid(marketprice,tradevalue) { 
 var KWDex = 0.281955
 var GBPex = 0.625907
 var USDex = 1
 var CADex = 0.998727
 var EURex = 0.784594

if 
  (currency == "KWD") 
  var currencyMarketprice = Math.ceil(marketprice*KWDex);
else if
  (currency == "GBP")
  var currencyMarketprice = Math.ceil(marketprice*GBPex);
else if 
  (currency == "USD") 
  var currencyMarketprice = Math.ceil(marketprice*USDex);
else if 
  (currency == "CAD") 
  var currencyMarketprice = Math.ceil(marketprice*CADex);
else if 
  (currency == "EUR") 
  var currencyMarketprice = Math.ceil(marketprice*EURex);

if (tradevalue % currencyMarketprice == 0)
  return ("tonnage = " + tradevalue / currencyMarketprice + " mt, and price = " + currencyMarketprice +" " +currency +" per mt");
else
  {for (var counter = currencyMarketprice+1; counter<(currencyMarketprice*2); counter++) {
    if (tradevalue % counter == 0)
     return ("tonnage = " + tradevalue / counter + " mt, and price = " + counter +" " +currency +" per mt");}}
}

</script>

</head>

<p>Select currency:
<input type="button" value="KWD" OnClick="setCurrency('KWD')">
<input type="button" value="USD" OnClick="setCurrency('USD')">
<input type="button" value="GBP" OnClick="setCurrency('GBP')">
<input type="button" value="EUR" OnClick="setCurrency('EUR')">
<input type="button" value="CAD" OnClick="setCurrency('CAD')">

<P>Enter today's price of commodity in USD: <input name="mktprc" input type="number"><br><p>
<P>Enter value of trade: <input name="trdval" input type="number">

<input type="button" value="Calculate" OnClick="document.getElementById('showMeArea').value=finddivid(document.getElementById('mktprc'),document.getElementById('trdval')));">

<p>
<br><br>

<input name="showMeArea" readonly="true" size="100">

</html>

If you run this html in your browser you should see what I am trying to achieve.

I’ve tried for a while to get this to work and I don’t know if the error if in the function or it the way I am trying to get the ‘return’ of the function ‘finddivid’ into the text box ‘showMeArea’…

Here are the main problems/features that I need help with:

  1. I would like to be able to click on one of the ‘currency’ buttons so that upon clicking, the variable ‘currency’ is assigned and then used in the function finddivid.

(2. This isn’t as important right now, but eventually, once this is working, I’d like it so that upon clicking one of the currency buttons, it changes colour, or is highlighted or something so that the user knows which currency rate they are using.)

  1. Upon entering the numbers into the two boxes I would like to click ‘Calculate’ and have it return what I’ve written in the function into the ‘showMeArea’ read-only box at the end of the code.

I know I’m probably missing loads of stuff and I might be miles away from success but I am very new to programming (started just a few days ago!) so would like any kind of help that can be offered.

Thanks in advance of your comments.

  • 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-14T23:55:35+00:00Added an answer on June 14, 2026 at 11:55 pm

    There are quite a few things wrong with your markup and javascript. You have unclosed paragraph tags, you set the scope of currency to be global but then define a local variable with the same name when you want to set it (which is why currency is never being set globally), you’re using an if/else statement where a switch/case is more appropriate… there’s probably a lot more, and the more you learn the more you’ll discover. Having said all that, because it bothered me, here’s a modified version of your code which seems to do what you were after :

    <html>
    <head>
    
    <title>Rounded Commodity Pricing</title>
    <script type="text/javascript">
    
        var currency;
        function setCurrency(val) {
            currency = val;
        }
    
        function finddivid(marketprice, tradevalue) {
            var KWDex = 0.281955
            var GBPex = 0.625907
            var USDex = 1
            var CADex = 0.998727
            var EURex = 0.784594
    
            var currencyMarketprice;
            switch (currency) {
                case "KWD":
                    currencyMarketprice = Math.ceil(marketprice * KWDex);
                    break;
                case "GBP":
                    currencyMarketprice = Math.ceil(marketprice * GBPex);
                    break;
                case "USD":
                    currencyMarketprice = Math.ceil(marketprice * USDex);
                    break;
                case "CAD":
                    currencyMarketprice = Math.ceil(marketprice * CADex);
                    break;
                case "EUR":
                    currencyMarketprice = Math.ceil(marketprice * EURex);
                    break;
    
            }
    
            if (tradevalue % currencyMarketprice == 0)
                return ("tonnage = " + tradevalue / currencyMarketprice + " mt, and price = " + currencyMarketprice + " " + currency + " per mt");
            else {
                for (var counter = currencyMarketprice + 1; counter < (currencyMarketprice * 2); counter++) {
                    if (tradevalue % counter == 0)
                        return ("tonnage = " + tradevalue / counter + " mt, and price = " + counter + " " + currency + " per mt");
                } 
            }
        }
    
        function calculate() {
            var mktprc = document.getElementById('mktprc');
            var trdval = document.getElementById('trdval');
            document.getElementById('showMeArea').value = finddivid(mktprc.value, trdval.value);
        }
    
    </script>
    </head>
    
    <p>
        Select currency:
        <input type="button" value="KWD" onclick="setCurrency('KWD')">
        <input type="button" value="USD" onclick="setCurrency('USD')">
        <input type="button" value="GBP" onclick="setCurrency('GBP')">
        <input type="button" value="EUR" onclick="setCurrency('EUR')">
        <input type="button" value="CAD" onclick="setCurrency('CAD')">
    </p>
    
    <p>Enter today's price of commodity in USD: <input id="mktprc" input type="number"><p>
    <p>Enter value of trade: <input id="trdval" input type="number"></p>
    <p><input type="button" value="Calculate" OnClick="calculate();"></p>
    
    <p>
        <input id="showMeArea" readonly="true" size="100">
    </p>
    
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a short piece of html code that, given two
I'm trying to write a short function that will let me quickly read in
I'm trying to write a short Wordpress JQuery for Wordpress comments that would allow
In short: Trying to write a wcf service for a winform-app that invokes a
I am trying to write a short function that will take a cell of
Long story short: I'm trying to write an app that'll dump IE's history to
I am trying to write code that will loop through all cells in a
I'm trying to write a short script that will query my mysql db, and
I'm trying to write a piece of software that allows one to click on
I am trying to develop a piece of code in Java, that will be

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.