본문 바로가기
알고리즘/Codewars

[Codewars] Grasshopper - Debug sayHello (8 kyu) / JavaScript

by fluss 2022. 11. 26.

https://www.codewars.com/kata/5625618b1fe21ab49f00001f

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

Debugging sayHello function

The starship Enterprise has run into some problem when creating a program to greet everyone as they come aboard. It is your job to fix the code and get the program working again!

 

Example output:

Hello, Mr. Spock
 

설명:

sayHello 함수를 디버깅하세요

starship Enterprise는 탑승하러 오는 모든 사람을 환영하기 위한 프로그램을 만드는데 몇 가지 문제에 부딪혔습니다. 코드를 수정하고 프로그램을 다시 작동시키세요!

 

출력 예시:

Hello, Mr. Spock
 

풀이

function sayHello(name) {
  return 'Hello'
}

원래 함수는 'Hello'라는 단어만 반환하도록 작성되어있다. 그래서 'Hello'에 입력받은 name을 붙인 'Hello, ' + name을 반환하도록 수정하였다.

 

코드

function sayHello(name) {
  return 'Hello, ' + name;
}

댓글