Profile lookup. Want to know whether something in my code could be used to start again

@ilenia Thank you for the info. And your advice ís very wise.


function lookUpProfile(name, prop){
// Only change code below this line
if (name == "firstName" || "lastName"); 
    if (prop == "number" || "likes") {
        return ["value"];
    } for (;prop != ["number"] || ["likes"];)

return "No such property";

if (name != ["firstName"] || ["lastName"]) {
    return "No such contact";
}
// Only change code above this line


lookUpProfile("Akira", "likes");

This is my code so far. I think I improved many things, I used pythontutor and the only error it marks out is SyntaxError: Unexpected end of input on line 45 (the “Akira”, “likes” line).

where is the closing } for your function? maybe indent your code, format it nicely, these issues are easier to see

after that, see if it runs, and if you can figure out what still needs to change

This (and the other lines like it) will always run as true because a nonempty string/array is truthy.

Did you repeat the fundamentals? The logic is broken throughout this code.

function lookUpProfile(name, prop){
// Only change code below this line
if (name == "firstName" || "lastName"); //This if statement is meaningless, will always run
    if (prop == "number" || "likes") { //This if statement is meaningless, will always run
        return ["value"]; // This will just return an array containing the word "value"
    } for (;prop != ["number"] || ["likes"];) // this is not a meaningful way to use a for loop. Also the condition will always be true

return "No such property"; // Why are you returning this here?

if (name != ["firstName"] || ["lastName"]) { // This if statement is meaningless, will always run
    return "No such contact"; // why?
}
// Only change code above this line


lookUpProfile("Akira", "likes");

This will always evaluate to true. This does not check if name is ‘firstName’ or ‘lastName’.

Same comment.

This will return an array with the string “value”. I don’t think this is what you meant.

I have no idea what this should be doing, but this is not a correct loop. You don’t write a for loop like that.

I think you really still need to go look at the lessons on

  1. if statements with multiple conditions

  2. the || operator

  3. for loops

  4. accessing object properties

  5. accessing array entries

Thank you very much everyone.
I think I’ll review all the lessons you suggested @JeremyLT.
Thank you all for your patience.
And of course this will return an array with the string “value” [“value”]. I really don’t know what I was thinking.

I know this will sound silly for some of you, but last time I passed this challenge it wasn’t as easier as it was now for me. I think I got the if/else if thing at least. So wanted to share my solution to golf code. Just to check things are getting easily understandable, at least some of them. I remember it was difficult for me the first time. I’m sorry if I’m being tiresome.

var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
  // Only change code below this line
if (strokes == 1) {
  return "Hole-in-one!"
} else if (strokes <= par - 2) {
  return "Eagle"
} else if (strokes == par - 1) {
  return "Birdie"
} else if (strokes == par) {
  return "Par"
} else if (strokes == par + 1) {
  return "Bogey"
} else if (strokes == par + 2) {
  return "Double Bogey"
} else if (strokes >= par + 3) {
  return "Go Home!"
}

  return "Change Me";
  // Only change code above this line
}

golfScore(5, 4);

I wanted to share what was for me a happy moment and the chance to show I’m not that stupid. No one commented. Well done or something. I said I know this sounds silly, no, not to some of you but to all of you, but to me it’s a lot. So I’m gonna keep that in mind and not your lack of a response. Self-steem is the only way to go ahead it seems. So thanks.

I don’t think anyone here was intending to downplay your success. Personally, I’ve have a very busy 2 hours at my job and have only been able to reply on the forum sporadically.

Feeling more comfortable when you go back and rework previous challenges is a good thing. Keep it up.

1 Like