JavaScript failed to read the entire variable

 <!doctype html>
 <html>
 <head>
 <meta charset="UTF-8">
 <title>Exchange rate</title>
 <link rel="stylesheet"type="text/css"href="exstyle.css"/>

 </head>

 <body>
 <script type="text/javascript">
     d=35;

     e=40;

     x=prompt("Insert Value");
     var z=x/d,
        g=x/e;


    var currency;
     currency=prompt("Insert Country");

     if(currency="dollar"){
        document.write(+z);
     }
     else 
         if(currency="euro"){
         document.write(+g);
    }


 </script>
 </body>
 </html>

I have encountered an issue while attempting to execute the code. For instance, when I input a value of 4000 for x and choose dollar as the currency, I receive the correct result of 114.28. However, upon selecting euro as the currency, the output remains the same as when dollar was chosen. Could there be an error in my implementation?

Answer №1

Ensure to use the comparison operator (==) in your code


if(currency == "dollar") {
    document.write(+z);
} else if(currency == "euro") {
    document.write(+g);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Bootstrap navigation bar is not functioning as expected

After building a landing page with a bootstrap navbar, I noticed that the hamburger menu doesn't display the list of items when the screen size is decreased. Here is the code I used: <nav class="navbar navbar-expand-lg" id="navbar&qu ...

Every time Grunt detects newer files, it automatically triggers the imagemin:dynamic task

I am working with a Gruntfile that looks like this: grunt.initConfig({ imagemin: { dynamic: { files: [ src: ['lib/public/img/*.{png,jpg,jpeg,gif}'], dst: 'build/public/img/', expand: true, fl ...

Incorporate a new button onto the jQuery-Knob slider

I'm seeking assistance with a project that requires implementing a circular slider with a draggable button-control. After some research, I opted to utilize the jQuery-Knob slider from this source. It works well, but I need to customize the button and ...

What is the purpose of wrapping my EventEmitter's on function when I pass/expose it?

My software interacts with various devices using different methods like serial (such as USB CDC / Virtual COM port) and TCP (like telnet). To simplify the process, I have created a higher-level interface to abstract this functionality. This way, other sect ...

Resetting dynamic form changes in Vue.js explained

Currently, I am using a template like this: <div> <div v-for="(item, key) in items" :key="key"> <div> <input type="text" :value="item.title"> </div> ...

Evaluating Angular directive scopes through function binding (&)

Currently, we are encountering some unusual behavior regarding the binding of a function to a directive scope. Check out an example on JSBin. Here's the scenario - we have a directive with a scope object structured like this: scope: { fn: '& ...

Having trouble finishing the npm installation process

Having trouble with completing 'npm install'. Can someone please assist me?</p> <pre><code>Encountering a warning about an old lockfile while running npm install. The package-lock.json file was created with an outdated version o ...

HTML page with a Bootstrap video banner displaying incorrectly

I'm currently working on modifying code sourced from Video Header snippet to suit my needs. The video header I've implemented is taking over my entire page, and I'd like to adjust its size to a width of 100% across the page and a specific h ...

Unit testing in Typescript often involves the practice of mocking

One challenge with mocking in Typescript arises when dealing with complex objects, as is the case with any strongly-typed language. Sometimes additional elements need to be mocked just to ensure code compilation, such as using AutoFixture in C#. In contras ...

Using Rails to reference an image in CSS

My application on Heroku, built with Rails, features a striking image as the background on the landing page. Since Heroku's file system is read-only, I made the decision to store these images (selected randomly) on AWS S3. In my .css(.scss) code, the ...

Failure to transfer form input values to PHP script

Currently, I am developing an email form that utilizes AJAX to connect to an external PHP file using PHPMailer for sending emails. In the beginning of the PHP file, I have the following code: if(count($_POST) > 0){ $message= 'Full Name: & ...

Is it a wise decision to provide the client with a new token just one minute before the expiration of the old one?

When monitoring my backend, I constantly check the remaining time before the JWT expires, which is set to 15 minutes. If there is only one minute left or less, I generate a new JWT and include it in the response header as a setToken. The front-end can then ...

The chaotic collision of concurrent JavaScript array concatenations causes confusion

After spending an excessive amount of time tracking down a bug, I am sharing my code with you all. Interestingly enough, I discovered that when using the push method, the array is complete. However, when using concat, there is a 50% chance that not all c ...

Invoke a PHP function from a class located in a separate file using an HTML button

I have an HTML input form with a SAVE button at the end. I want the SAVE button to trigger a PHP function written in a separate class file. The PHP code at the beginning of the file nabava_vnos.php that contains the HTML form: <?php // Script for sta ...

Having trouble incorporating custom elements with the document.execCommand function

I have been attempting to insert a custom element into an editable div using the document.execCommand method as described in detail on https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand. However, when I try to add a custom polymer eleme ...

Content that moves with a flick of a finger

Seeking advice on a widely used JavaScript library that can facilitate scrolling for frequently updated content, similar to what popular websites like have implemented. I've had difficulty finding the right query on Google, so any recommendations or ...

A tutorial on preventing backbone.js from automatically adding /# when a dialog is closed

Whenever I navigate back on my backbone page, it automatically adds /# to the URL. This results in loading an empty index page from the Rails home view when pressing back again. Disabling turbolinks fixed this issue for me. However, another problem arises ...

Tips for displaying two div elements side by side on the same line

Two div elements are structured like this: <div class="pdetails"> <div class="contact_details"> text </div> <div class="clear"></div> <div id="contact_area_form_" class="tform_wrapper"> text ...

Incorrect elements displayed by Preact

Currently, I am utilizing Preact (essentially React) to display a list of items stored in a state array. Each item is accompanied by a remove button. My issue arises when the remove button is clicked; the correct item is deleted (I have double-checked this ...

Having trouble with updating PHP MySQL data using serializeArray?

My HTML page includes a display of temperature with two buttons - one for updating MySQL with the temperature setting and the other for toggling on/off data. Previously, everything was functioning correctly with the initial code: function myFunction() { ...