TIL#3 JS) String

luneah·2021년 10월 29일
0

JavaScript

목록 보기
3/16
post-thumbnail

문자열 Practice

01. getFullName

두 문자열을 + 연산자로 합칠 수 있다.

EX)

let firstWord = 'Hello ';
let secondWord = 'World';

let word = firstWord + secondWord

console.log(word);    // Hello World 출력

02. getLengthOfWord

EX) fullName에 이름을 넣어라.

  • fullName의 길이를 console.log로 출력하라.
  • 직접 계산하지 계산하지말고, length를 사용하여 길이를 구하라.

Sol )

let fullName = '홍길동';

console.log(fullName.length)   // 3 출력

03. averageLength

EX)

  • length1에는 word1의 길이 값을 할당하고, length2에는 word2의 길이 값을 할당하라.
  • 직접 계산하지 말고 length를 사용하여 계산하라.
  • console.log에서 두 길이 값의 평균을 구하고 있는 것을 확인하라.
    두 숫자를 더해서 2로 나눠 평균을 구하고 있다.

Sol )

let word1 = 'tree'
let word2 = 'flower'

let length1 = word1.length    // length1에 word1의 길이 값 할당
let length2 = word2.length    // length2에 word2의 길이 값 할당

console.log( (length1+length2) / 2 )   // 5 출력
profile
하늘이의 개발 일기

0개의 댓글