Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS Calculate something locally and show the results on server (newbe question)

KRSOne

New Coder
Hello,
can somebody please help me. I'm new to nodejs. I have to do the following task (without any further explonation);

"Please implement the HTML form and calculate with JavaScript (locally in the browser) and on
the server with Node.js the result"


It's a currency excahnge app. I can build that with JS and HTML in a few minutes, no problem.
But I have absolutely no idea what is meant with "result on the server".
I tried to get any heck out of it with tutorialspoint, but I still have no clue at all.
Please, can somebody tell me what I am supposed to do here.


Thank you
 
Here is my code, which is not what the professor wants :(
It's missing the "on the server with Node.js the result" part. Sorry for bad english. It's the exact term I'm given.
Please help

Code:
<div class="MainDiv" style = "width: 500px; margin: 200 auto;">
    <div class="container">
        <h2>Converter Form (2022)</h2>
       
    <form class="MainForm">
        Currency Amount:      
        <div class="CurrencyAmount">
            <input type="number" class="" id="amount"/>
        </div>
       
        </br>
        Customer:
        <div class="Customer">
            <input type="text" class="" id="customer"/>
        </div>
       
        </br>
       
        Currency: </br>
        <div class="form-member" style = "float: left;">
            <select class="form-control" id="currency-1" required>
              <option>EUR</option>
              <option>USD</option>
            </select>
        </div>
         
        <div class="form-member" style = "float: left;">
            <label> &nbsp > </label>
            <select class="form-control" id="currency-2" required>
              <option>EUR</option>
              <option>USD</option>
            </select>
        </div>
         
        </br></br>
         
        <div>
            <button class="bton calculate-cur mb-2">Convert</button>
            <button class="bton reset mb-R">Reset</button>
        </div>
         
    </form>
   
    <div class="result">
      <p>
        <span class="start-amount"></span>
        <span class="base-currency"></span>
        <span class="final-result"></span>
        <span class="second-currency"></span>
      </p>
    </div>
  </div>
 
  <!--
  * (1 EUR = 0.84 USD is used in this example)
  <p><img src="kurs.jpg" width="80%" title="" /></p>
  -->
 
</div>



<script>
// Assumptions
var assumptions = {'EUR': {'USD': 0.84}, 'USD': {'EUR': 1.2}}
// Get Button Elements
var bton = document.querySelector('.calculate-cur');
// Get Inputs
var firstCurrencyInput = document.getElementById('currency-1');
var secondCurrencyInput = document.getElementById('currency-2');
var amountInput = document.getElementById('amount');

// Vars to show results
var showAmount = document.querySelector('.start-amount');
var showBase = document.querySelector('.base-currency');
var showSecond = document.querySelector('.second-currency');
var showResult = document.querySelector('.final-result');

function convertCurrency(event)
{
    event.preventDefault();
    // Assign Values
    var amount = amountInput.value;
    var first = firstCurrencyInput.value;
    var second = secondCurrencyInput.value;
    var result = 0;
     
    try    {
        // Case we don't need to calculate. When USD to USD
        if (first == second){
            result = amount;
        }
        // Calculate result based on assumption value
        else {
            result = amount * assumptions[first][second];
        }
    }
    catch(err) {
        result = amount * (1 / assumptions[second][first]);
    }
     
    // Show results
    showAmount.innerHTML = amount;
    showBase.textContent = first + ' = ';
    showSecond.textContent = second;
    showResult.textContent = result;
}

bton.addEventListener('click', convertCurrency);

</script>
 
I'd have thought a "professor" would be able to clearly formulate an assignment. Either they're not, OR (perhaps more likely) this is a vital part of the assignment. Asking questions is vital to any task, don't be afraid to ask them. That is much better than just 'doing something' or asking others to explain what the prof may have meant.
 
I saw your last message just before you deleted it again. Get another professor. This guy is an idiot.
 
Last edited by a moderator:
I'd have thought a "professor" would be able to clearly formulate an assignment. Either they're not, OR (perhaps more likely) this is a vital part of the assignment. Asking questions is vital to any task, don't be afraid to ask them. That is much better than just 'doing something' or asking others to explain what the prof may have meant.

Nope, and there's no use in further asking, because you will only get insulted and shouted at. :( That's why I have to ask here.
What he want is some sort of server where it's calculated and results to be shown in a browser.

Code:
res.writeHead(200, { 'Content-Type': 'text/html' })
fs.readFile('index.html', function(error, data){

Creating a server and reading in the index.html from above is maybe a solution. I'm not sure, would the calculation take place on server like that?
 
Sorry, can't help you. I do not believe in doing an assignment if it is unclear what is needed. Especially not if the instructor will shout and insult rather than explain (which he'll probably do even more if you don't deliver whatever he wants).
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom