According to this exercise solution, I first have to create a variable within the function called “account_name” and then outside the function equate “new_account” to the function in order to get the correct answer.
Well, your function is correct and it should be accepted as the solution of the first step of instructions.
But in order to finish this exercise, you have to create a new variable new_account and assign to it the result of calling your function with arguments "Julie" (first_name) and "Blevins" (last_name).
If the instruction is not clear feel free to use Get Code Solution option that you will find under Get Help button (right bottom corner). If the solution code does not make sense - get back to us, we will try to help
Hi, one thing that I haven’t seen explained yet is:
Concatenating strings with plus “+” versus comma “,”
Example from exercise:
fruit_sentence = "My favorite fruit is" + favorite_fruit
print(fruit_sentence)
# Output: My favorite fruit isblueberries
fruit_sentence = "My favorite fruit is " + favorite_fruit
print(fruit_sentence)
# Output: My favorite fruit is blueberries
When using “+” you have to manually add spaces and convert integers to strings.
When using “,” you do not need to convert to strings or apply spaces.
Can anybody give an example of when you would utilise one over the other?
At this stage I see using a comma “,” as a faster and more accurate option of the two.
To break the myth, concatenating with a comma is not a thing. The only place a comma can be used is in the argument for, console.log(). it looks like concatenation but is actually just a space character between items in a comma separated list, sans comma.
Why is this the case? If account_name contains the function of first_name[:3] + last_name[:3] then why do I need to add in
new_account = account_generator(first_name, last_name) instead of new_account = account_name?
If the temporary variable is holding what is to the right of it and code is read from a top down approach wouldnt that mean that anything above new_account = account_name would be applied? Isnt that why we can have variables not in the function that are able to be accessed anywhere in the code so long as they are out of the function?
I am having trouble understanding the point of “return”.
Following the syntax learned, I am finding the correct solutions, but I also find additional solutions with the same results.
Why does one function work better than the other? Why isn’t the use of “return” considered too repetitive?
I can’t see the lesson that this FAQ is attached to b/c I didn’t do the CS path. I’m assuming that it’s asking you to write a function that takes some input and returns something, yea?
That said, return exits the function and returns a value to the caller.
print() is not the same thing as return. print() is a function that will print a string to the console.
In the code in the exercise, it feels a bit confusing to have first_name and last_name globally defined, and also have them as the names for the local variables within the account_generator function. Would it not be clearer to have them with separate names?