Build an RPG Character - Code Error

Tell us what’s happening:

I’m getting the following error message… " 3. Your code raised an error before any tests could run. Please fix it and try again."

I think it has to do with the “name” if statements section of code, but I can’t for the life of me pinpoint the issue. Would love some guidance on this one. Thanks!

Your code so far

full_dot = '●'
empty_dot = '○'

def create_character(name, strength, intelligence, charisma):
    if not isinstance(name, str):
        return "The character name should be a string"
    elif name == "":
        return "The character should have a name"
    elif len(name) > 10:
        return "The character name is too long"
    elif ' ' in name:
        return "The character name should not contain spaces"

    if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):
        return "All stats should be integers"
    elif strength < 1 or intellgence < 1 or charisma < 1:
        return "All stats should be no less than 1"
    elif stregth > 4 or intelligence > 4 or charisma > 4:
        return "All stats should be no more than 4"
    elif strenght + intelligence + charisma != 7:
        return "The character should start with 7 points"



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36

Challenge Information:

Build an RPG Character - Build an RPG Character

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-rpg-character/67d83df6f82eda3868dd2a84.md at main · freeCodeCamp/freeCodeCamp · GitHub

have you tried calling the function?

there in an error that appear in the terminal when you call the function

Thanks for pointing that out @ILM! I fixed those spelling errors (will try to be more diligent about that moving forwards). Hm, I’m still getting the same error message in the console. :frowning:

can you share your updated code please?

full_dot = '●'

empty_dot = '○'



def create_character(name, strength, intelligence, charisma):

    if not isinstance(name, str):

        return "The character name should be a string"

    elif name == "":

        return "The character should have a name"

    elif len(name) > 10:

        return "The character name is too long"

    elif ' ' in name:

        return "The character name should not contain spaces"



    if not isinstance(strength, int) or not isinstance(intelligence, int) or not isinstance(charisma, int):

        return "All stats should be integers"

    elif strength < 1 or intelligence < 1 or charisma < 1:

        return "All stats should be no less than 1"

    elif strength > 4 or intelligence > 4 or charisma > 4:

        return "All stats should be no more than 4"

    elif strenght + intelligence + charisma != 7:

        return "The character should start with 7 points"



create_character("Sam", 3, 4, 5)

Please check for the error in your browser’s console.

test with valid values, like print(create_character("Sam", 3, 3, 1)), then you will see an other error related to typos

Thank you both! @ILM / @dhess How did you know to try those approaches for detecting further errors?

the first failing test, number 3, was about what should happen when values are valid, so to test what’s happening I call the function with valid arguments, if it does not show anything, I wrap it in print, if with print it still seems exactly as asked I do print(repr(<function call here>))

if that does not give enough infos, I start adding print inside the function to check the value of all variables until I find the one that has the unexpected value

it’s a standard debugging flow

@ILM Thanks, that’s super helpful! Do you use the web browser’s console much for debugging?

do you mean open the console and see what errors are displayed? it can give useful infos

sometimes I also use https://pythontutor.com/, which allows you to see what is happening to the values line by line