0

im trying to built a Multiconverter in javascript, but for some reason i can´t stop the loop, and i can´t get the result for the functions. i did the following:


    // conversion Dollars to Euros( 1USD = 0.892901) as of 11.08.2019; conversion Swiss Franc to Euro ( 1chf = 0.918063) as of 11-08-2019, conversion Knots to Kph (1knots = 1.85Kph);

    //Dollars to Euros

    function DollarstoEuros ( Dollars) { 
        return USD * 0.892901;
    }

    // Swiss Francs to Euros

    function SwissFrancsToEuros ( Francs ) {
        return Francs * 0.918063;
    }

    // Knots to Kph

    function KnotstoKph ( Knots ) {
        return Knots * 1.85;
    }

    // Ask the user which conversion they want to use
    function WhichConversion () {

    var answer = window.prompt( " Welcome to the Mutliconverter! What do you want to convert?  ( Dollars, Francs, Knots");
    if (answer == "Dollars", "Knots", "Francs"){
        return true;
    } else {
        return false;
    }
}

//Ask for a Value
function AskForValue () {
    var answer = window.prompt( " Enter a Value to Convert")
    return answer;
}

Should i change the function WhichConversion in order to separate the if answer? because the while and the var inside it seems ok to me, maybe or probably it´s a basic mistake, but im in my earlier steps in javascript, and apart of beeing similar, i prefer python.

Teixeira66
  • 21
  • 5
  • Your check to see if answer is either dollars, knots or fancs doesn't do what you think it does.You should check out https://stackoverflow.com/questions/9121395/javascript-the-prettiest-way-to-compare-one-value-against-multiple-values/9121683 – scrappedcola Aug 13 '19 at 19:17
  • What are you looping over? – Emiel Zuurbier Aug 13 '19 at 19:46
  • ´´´// Continue as long the user wants //Ask the user which conversion they want to use while (WhichConversion()) { var ConversionType = WhichConversion(); var ConversionValue = AskForValue(); var resultMessage = " The result is "; var result = 0; ´´´ – Teixeira66 Aug 13 '19 at 20:01
  • if (ConversionType == "Dollars"){ resultMessage += DollarstoEuros(Number(ConversionValue)) .toString(); }else if (ConversionType == "Francs"){ resultMessage += SwissFrancsToEuros(Number(ConversionValue)) .toString(); }else if (ConversionType == "Knots"){ resultMessage += KnotstoKph(Number(ConversionValue)) .toString(); }else{ resultMessage = " Pay attention! That conversion is not supported."; } } //Display the result console.log(resultMessage); – Teixeira66 Aug 13 '19 at 20:02

0 Answers0