Returning Strings

chris0205.eth·2022년 2월 27일
0

Codewars

목록 보기
3/5
post-thumbnail

Prob

Make a function that will return a greeting statement that uses an input; your program should return, "Hello, (name) how are you doing today?".

[Make sure you type the exact thing I wrote or the program may not execute properly]


Answ

my

function greet(name){
  return grt = 'Hello, '+name+' how are you doing today?';
}

문자열을 리턴하는 함수를 설계했다.

others

1

function greet(name){
  return `Hello, ${name} how are you doing today?`;
}
  • ${ } 의 결과는 문자열로 자동 변환된다.

2

function greet(name){
  return "Hello, <name> how are you doing today?".replace("<name>", name);
}

.replace 메소드를 이용하여 함수를 설계했다.

profile
long life, long goal

0개의 댓글