Codecademy Practice Quiz return the string "i can haz cheezburger?"

function quiz|690x273

Hi all,

After all the tutorials up to function i realise i still do not understand how to code from the quiz.

Have some questions regarding this practice quiz, how do i write it?

The prompt gives you several clues:

  1. Write a function named icanhaz()
  2. It should take one (1) string argument
  3. Your function should return something. if invoked with no argument it should return the string I can haz cheezburger?
  4. If involved with an argument, it should return I can haz [argument], where [argument] is replaced by the argument passed to the function (think string concatenation, or template literals).

So! Do you think you can come up with a solution now? Feel free to share here or keep asking questions, we are all super friendly :smile:

2 Likes

Thank you haha

I am still confused how to start or what to write for point 2 and 3 and 4. Am very lost. Will skip this first.
Think i going to give up JS altogether if i continue this quiz without a single direction.

Are you familiar with the basic syntax of a function in JavaScript? I bet you covered it in the lessons leading up to this quiz.

function nameYourFunction (parameter1, parameter 2) {
   // do things inside the function
   return anythingYouWant
}

So for example, imagine that I wrote a function that return a greeting, and checks if your name is the same as mine to add a bit of flair:

function greeting(name){
   if (name === ‘Fede’){
      return ‘hello ‘+name+’! Wow, we have the same name!’;
   } else {
      return ‘hello ‘+name+’!’;
   }
}

console.log(greeting(‘Bob’));  // returns ‘hello Bob!’

Does that make sense? You are trying to do something similar in the quiz, but a little different too.

Yes i completed the entire function syllabus, am at the rock paper scissors.

Great thank you. I can understand your clue now. Let me try again. I realise i can read code but i cannot write code when prompted to answer.

But am still clueless how returns work exactly after doing google search and youtube tutorial. I do not understand what it means when they say ‘return a value’. So where does value goes, not sure why i see console.log and variables in function and how exactly to get it to work ^^

Wondering why use Return and console.log and why it prints onto the screen on the right and why it does not print.

Hello! I will use an analogy to explain return and console.log(). Imagine you ordered a cake from a bakery-that will be the function-orderCake(). When you order a cake, it is like calling the function. Now, if you are waiting, and you see a message pop up on the screen saying “your cake is ready”, that is like console.log(). It prints something, but it doesn’t actually give you anything. Now, when you actually receive the cake, that is like return. The cake is being handed over to the person who ordered the cake:

function orderCake(){
console.log("your cake is ready!");//this is like a message being printed on a screen-it tells the user something, but the program can't actually use this value.
return "cake!";//this is like being handed the cake-it isn't printed, but the rest of the program can use this value later on.
}

I hope this helps!

1 Like

Hey hi thank you so much for the explaination. It makes more sense now!

I realise it is much more difficult when trying to write new code from a quiz.

Thank you once again! : )

1 Like