PS/제코베 JS 100제

제코베 JS 100제 / 59 / 빈칸채우기

KimMinJun 2022. 8. 31. 15:19

총 문자열의 길이는 50으로 제한하고 사용자가 문자열을 입력하면 그 문자열을 가운데 정렬을 해주고, 나머지 빈 부분에는 '='을 채워 넣어주세요.

 

function fillBlank(str) {
  let result = "";

  result += "=".repeat((50 - str.length) / 2);
  result += str;
  result += "=".repeat((50 - str.length) / 2);

  console.log(result);
}

const str = "hi";
fillBlank(str);