Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roman Numeral Converter: Tests results incorrect #9090

Closed
savourylie opened this issue Jun 11, 2016 · 6 comments
Closed

Roman Numeral Converter: Tests results incorrect #9090

savourylie opened this issue Jun 11, 2016 · 6 comments

Comments

@savourylie
Copy link

savourylie commented Jun 11, 2016

Challenge Name

Roman Numeral Converter

Issue Description

The FCC IDE showed that my code didn't pass some of the tests while the tests are passed no problem on my Chrome 53.0.2762.0 canary (64-bit), and on NodeJS (v4.2.3). What's more interesting is that when I used the same code on the Chinese branch of FCC (freecodecamp.cn), it worked perfectly.

Browser Information

  • Browser Name, Version: Chrome 53.0.2762.0 canary (64-bit)
  • Operating System: OS X 10.11.4
  • Mobile, Desktop, or Tablet: Desktop

Your Code

// If relevant, paste all of your challenge code in here
"use strict";
"use esversion: 6";

class RomanDict {
    constructor() {
        this.M = 1000;
        this.D = 500;
        this.C = 100;
        this.L = 50;
        this.X = 10;
        this.V = 5;
        this.I = 1;
    }

}

function stringMultiplier(str, n) {
    var result_str = "";

    for (var i = 0; i < n; i++) {
        result_str = result_str + str;
    }

    return result_str;
}


function numOfSymbol(num, symbol) {
    var roman_dict = new RomanDict();

    // console.log([parseInt(num / roman_dict[symbol]), num % roman_dict[symbol]]);
    return [parseInt(num / roman_dict[symbol]), num % roman_dict[symbol]];
}


function convertToRoman(num) {
    var roman_dict = new RomanDict();
    var result_str = "";
    var temp_num = num;

    for (var property in roman_dict) {
        if (roman_dict.hasOwnProperty(property)) {
            result_str = result_str + stringMultiplier(property, numOfSymbol(temp_num, property)[0]);
            temp_num = numOfSymbol(temp_num, property)[1];
        }
    }

    // ETL for XI and VI etc...
    result_str = result_str.replace("DCCCC", "CM");
    result_str = result_str.replace("CCCC", "CD");
    result_str = result_str.replace("LXXXX", "XC");
    result_str = result_str.replace("XXXX", "XL");
    result_str = result_str.replace("VIIII", "IX");
    result_str = result_str.replace("IIII", "IV");

    // console.log(result_str);
    return result_str;
}

// convertToRoman(36);

console.log(convertToRoman(2) === "II")
console.log(convertToRoman(3) === "III")
console.log(convertToRoman(4) === "IV")
console.log(convertToRoman(5) === "V")
console.log(convertToRoman(9) === "IX")
console.log(convertToRoman(12) === "XII")
console.log(convertToRoman(16) === "XVI")
console.log(convertToRoman(29) === "XXIX")
console.log(convertToRoman(44) === "XLIV")
console.log(convertToRoman(45) === "XLV")
console.log(convertToRoman(68) === "LXVIII")
console.log(convertToRoman(83) === "LXXXIII")
console.log(convertToRoman(97) === "XCVII")
console.log(convertToRoman(99) === "XCIX")
console.log(convertToRoman(500) === "D")
console.log(convertToRoman(501) === "DI")
console.log(convertToRoman(649) === "DCXLIX")
console.log(convertToRoman(798) === "DCCXCVIII")
console.log(convertToRoman(891) === "DCCCXCI")
console.log(convertToRoman(1000) === "M")
console.log(convertToRoman(1004) === "MIV")
console.log(convertToRoman(1006) === "MVI")
console.log(convertToRoman(1023) === "MXXIII")
console.log(convertToRoman(2014) === "MMXIV")
console.log(convertToRoman(3999) === "MMMCMXCIX")

Screenshot

screen shot 2016-06-11 at 11 53 39 pm

@ghost
Copy link

ghost commented Jun 11, 2016

your code works fine for me in FCC 'ide'
also tested running through node. 4 results in IV and type is string

@erictleung
Copy link
Member

@savourylie you code passes just fine for me on the FCC website. But I'm a bit unclear on what you mean between the FCC "IDE" and just Chrome and Node.

@ghost ghost added the status: blocked Is waiting on followup from either the Opening Poster of the issue or PR, or a maintainer. label Jun 12, 2016
@ghost
Copy link

ghost commented Jun 12, 2016

@erictleung Not sure about Chrome, I assume running local file and viewing in dev console?
Node however, if you install node js you can execute js at the command line.

@savourylie
Copy link
Author

@robjloranger Thanks for clarifying for me. Yes that's what I meant by running in Chrome (dev tools console). I usually test my JS in node.js which allows me to test my code "headlessly". I find that very convenient. :)

Oh and strangely, when I opened up FCC just now, everything was running green! So I pressed Test/Run button again and it showed all passed and jumped to the next challenge.

I don't know what happened as I didn't change my code nor anything. But I guess this mean the problem is fixed now. Thanks guys. Deeply appreciated!

@ghost
Copy link

ghost commented Jun 12, 2016

Glad it's sorted, sometimes a browser refresh or restart helps. It can be
cashed code.
How do we close this now?

Rob Loranger
250-589-4806
Saanich, B.C.
www.robloranger.ca
On Jun 11, 2016 10:15 PM, "Calvin Ku" notifications@github.com wrote:

@robjloranger https://github.com/robjloranger Thanks for clarifying for
me. Yes that's what I meant by running in Chrome (dev tools console). I
usually test my JS in node.js which allows me to test my code "headlessly".
I find that very convenient. :)

Oh and strangely, when I opened up FCC just now, everything was running
green! So I pressed Test/Run button again and it showed all passed and
jumped to the next challenge.

I don't know what happened as I didn't change my code nor anything. But I
guess this mean the problem is fixed now. Thanks guys. Deeply appreciated!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9090 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AMqbrmsp-xvlkVLpvxuBPXE9_iXyaLbIks5qK5XkgaJpZM4IzlFA
.

@erictleung
Copy link
Member

@savourylie glad things are working now! I'll go ahead and close this issue as it seems resolve. Happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants