28. Conclusion: Part 2 -- Why is it wrong? Writes that syntax errors and token


#1

Please help me, too? Why is it wrong? Writes that syntax errors and token. I'll be grateful for your response. For the correct code.
This is my code:
1 var myName="Alena";
2 if("myName").length<3))
3 {
4 console.log("is not true");
5 }
6 else
7 if("myName").length===5))
8 {
9 console.log("I finished my first course!");
10 }


Conclusion part 2
#2

Hello Alena alias alice010101,
din't you forget a semi-colon to end your code lignes 2 and 7 by the way ?
try this code perhaps:
1 var myName="Alena";
2 if(myName."length"<3);
3 {
4 console.log("is not true");
5 }
6 else
7 if(myName."length"===5)
8 {
9 console.log("I finished my first course!");
10 }

remember in Conclusion part 1 for example :
1 // Sur la ligne 2, écrivez votre premier commentaire; ça peut être n'importe quoi !
2 // N'importe quoi !
3 var maCouleur="Bleue";
4 {console.log(maCouleur.length);}


#3

Why did you put variable myName inside of double quote?

I don't know JS, actually i hate JS, but i think that correct syntax is

if(myName.length < 3){ do something}


#4

detchen
I think that is a bad idea to quote a builtin function:
if(myName."length"<3);
length is a builtin function for JS.


#5

Thank you very much for your help, but unfortunately, this code has been really bad. It is true that putting quotation marks around the actual JavaScript command was not such a good idea. But even so, thank you very much for your time and for your willingness.


#6

You are a champion! Javascript not know, but you know how it. Your code has been absolutely right. Next time I have to be careful on those errors. Thank you very much, you've helped me so. Really thanks. You are really good.:smile:


#7

Thanks echosomething and alice010101

I turn back to code and it's ok

Sorry for the late I was too busy.

So, taking time to, now I'm at the JS Unit 2 "Introduction aux fonctions en JS"
at the 3th exercice, I'm tired...so may be I don't understand the instruction, I don't find the good code on the 11th ligne :

  1. / Voici la fonction saluer !
  2. // Regardez la ligne 7
  3. // Nous pouvons rassembler des chaînes de caractères en utilisant le signe plus (+)
  4. // Regardez les indices pour avoir plus de détails sur ce sujet
  5. var saluer = function (nom) {
  6. console.log("Content de vous voir," + " " + nom);
  7. };
  8. // Sur la ligne 11, appelez la fonction saluer !

I don't see how rightly to code... once again.

bests
Detchen


#8

It's alright. Unfortunately, I can not help it. Now I Codecademy neglected. I know the "nom". I'm sorry.
Alena


#9

saluer("detchen");


#10

Hi detchen
First of all you have to understand what is a variable, please read this, i wrote a few words on this:
Read this

Actually "var sauler" isn't a function, your function is "function(mom){...}".
You may assign to a variable values like string, integer, etc. A function actually is also an object, like "string", "integer", so you may assign a function to a "variable". Your function "function(mom)" require an argument for its parameter "mom", is obvious that you have to provide an argument. I am not a fun of JS but i think that:

You may call your function like this:

var my_nom = "detchen";
function(my_var);
But exercises ask to assign your function to a variable and call this variable like as a function.

var sauler = fucntion(nom){....};

Now your variable "sauler" is tied to function and behave like a function, further we have to provide an argument for function parameter, lets store the argument into a variable "my_nom"

var my_nom = "detchen";

now lets call the function trough the "variable" "sauler" and provide the argument from function parameter trough our variable "my_nom":

sauler(my_nom);

Hope this help you. Please read the post on link that i give you.


#11

Hello and thank you echosomething,

I read well, but not sure I understood, my English is like me : a rr multiple sclerosed.

I'm still at the same point which give on the right black side written in red :

SyntaxError: function statement requires a name.

but I finaly found the right code.

Now I'm stopped like this again at the "Don't Repeat Yourself (D.R.Y)" exercise because repeating is my speciality lol where my code is wrong to get how many cost 5 oranges:

var coutOrange = function(prix*5)
{
console.log(prix*5===result);
prix = 5;
};

it's so I try this one:

var coutOrange(5) = function (prix) {
var prix = *5;
console.log(prix);

it's also wrong

:ear_of_rice: :coffee: :four_leaf_clover::cherry_blossom:


#12

Hi detchen
You make a few mistakes in your code.
A function is like an reusable template. Lets take an general example, not for JS

-----------------------------

function(a, b){
c = a + b
return c
}

we call function to get result

function(2, 3)

--------------------------

in our example "a, b" are formal parameter, further we want to get result of addition for these parameter "c = a+b".
But what is value of "a and b"?
We assign value to "a and b " calling the function

function(2, 3)
This mean that we get value for a -> 2 and for b -> 3, now our function know "a and b", result that

c= 2+ 3

further our function return addition value for 2 and 3 trough variable "c" to the caller "function(2, 3)"

-------------------------------------

In your code you wrote
function(prix*5)
Well this is wrong, inside "()" you cant make operation, this area is just for formal parameters.

Correct code is like:
var orangeCost = function(prix)
{
console.log(prix*5);
};
orangeCost(4)

----------------------------------------

Like in my example, your function have just one parameter "prix". To execute the multiplication (prix * 5) you have to provide a value for "prix", for example "10". Then "(10 * 5)" have meaning for interpreter.
You assign this value "10" calling function like this:

orangeCost(10)

then your code will look like this:

----------------------

var orangeCost = function(prix)
{
console.log(10 * 5);
};
orangeCost(10)

------------------------------------

If you want get result for other value you have to change argument in your caller:

orangeCost(22) or orangeCost(10023) , etc.

When you change the argument value eg. "22" in caller orangeCost(22), then this value will be passed automatically to the function to "prix" and then interpreter will know that you want to get multiplication 22 * 5

Hope this help you

There may be other methods to pass value for parameters
e.g.

var orangeCost = function(prix=4)
{
console.log(prix*5);
};
orangeCost()

In this example you have to call your function without arguments because you already assigned a value for "prix = 4",
you have to call function like this:
orangeCost()


#13

Hi Thank you very much, I got it !
so I give this answer (my code bellow) and it works (but I can't se the result on the black left page of the course or exercise, do you see what I mean please ?

look at my code:

var coutOrange = function (prix)
{
console.log(prix*coutOrange);
prix = 5;
coutOrange(5)
};

what's wrong, a bug or I miss to code a line to tell the console to show the result ?
as for example :
prompt("result console.log");
but the instruction doesn't asked it ant this one and any other I testes doesn't work.


#14

Hi detchen

Well, your code is wrong, compare my code and your and see what is wrong:
my code:

-----------------------------------------------

var orangeCost = function(prix)
{
console.log(prix*5);
};
orangeCost(4)

-----------------------------------------

your code:

-----------------------------------------

var coutOrange = function (prix)
{
console.log(prix*coutOrange);
prix = 5;
coutOrange(5)
};

-------------------------------------

Why did you write?:
console.log(prix*coutOrange)

correct is:
console.log(prix*5);

Verb "console.log(prix*coutOrange) " is like "print this" or "echo this" or "get the answer for this operation"
So when you write "console.log(prix*coutOrange) " you expect that to get an answer from interpreter it sound like "Hey give me result of multiplication between prix and coutOrange". But what is your "prix" and "coutOrange"?
You give value for "prix" calling function trough "coutOrange(4)". Now interpreter knows that "console.log(4*coutOrange)", but what is value for coutOrange? This is wrong.
Correct syntax is "console.log(prix*5) " not "console.log(prix*coutOrange) ".
By the way you place wrong the caller, you put this inside of body function:

------------------------------------------------------------

var coutOrange = function (prix)
{
console.log(prix*coutOrange);
prix = 5;
coutOrange(5)<------------- WRONG POSITION !!!
}; <-------------------------------------------------- LOOK AT THIS

This have to be outside of body function

--------------------------------------------------------

Correct is:

var orangeCost = function(prix)
{
console.log(prix*5);
}; <----------------LOOK AT THIS
orangeCost(4)<----------------------- CORRECT POSITION