Answer the question
In order to leave comments, you need to log in
Please help with learning JS on stepic. How to solve this problem?
Please help me with an example. On the stepic platform, the admins are silent, and I have been racking my brains for the 2nd day, I don’t need to decide for me, but just tell me how to solve the problem
like this
. - number of the previous robot of this model (number).
You need to return the full name of the new robot as a string. To do this:
Increment
the
variable n by 1 and
add it to str , and write the result to the variable result, which is then
returned
from the function with
return 2:
Roboto 1
Sample Output 2:
Roboto2
Sample Input 3:
r2d 1
Sample Output 3:
r2d2
function modify(str,n){
var result;
// Здесь ваш код
return result;
}
function modify(str,n){
var result;
var = n++;
str+n;
return result;
}
Answer the question
In order to leave comments, you need to log in
var = n++;
^ there is an error,
firstly this is the wrong syntax, n++
this is a self-sufficient expression that will increase n
secondly
According to the language specification, the difference between pre- and post-increment is that when the expression is evaluated, the result is the old value in one case, and the new value of the variable being incremented in the other
n = 1;
n1 = n++;
console.log(n, n1) // 2, 1
function modify(str,n){
var result;
var = n++; // ?
str+n; // ? ок это никуда не сохраняется и ничего не делает
return result; // чему равен result?
}
строку + (номер + 1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question