나
<script>
$(".card:nth-child(1) h5").html(products[0].title);
$(".card:nth-child(1) span").html(products[0].price);
$(".card:nth-child(2) h5").html(products[1].title);
$(".card:nth-child(2) span").html(products[1].price);
$(".card:nth-child(3) h5").html(products[2].title);
$(".card:nth-child(3) span").html(products[2].price);
강의방법
document.querySelectorAll('.card-body h5')[0].innerHTML = products[0].title;
document.querySelectorAll('.card-body p')[0].innerHTML = '가격 : ' + products[0].price
document.querySelectorAll('.card-body h5')[1].innerHTML = products[1].title;
document.querySelectorAll('.card-body p')[1].innerHTML = '가격 : ' + products[1].price;
document.querySelectorAll('.card-body h5')[2].innerHTML = products[2].title;
document.querySelectorAll('.card-body p')[2].innerHTML = '가격 : ' + products[2].price;
</script>
console.log(1 + '2');
JS에서는 덧셈기호를 사용하면 문자이어붙이기가 쉽게 가능하다!
숫자 + 숫자 -> 숫자덧셈
문자 + 숫자 -> 적어도 1개가 문자면 문자덧셈
문자 덧셈이란 ?
문자 2개를 이어붙여줌
let a = '안녕';
console.log('문자' + a + '문자'); // '문자안녕문자'출력
let a = '안녕';
console.log(`문자 ${a} 문자`); // '문자안녕문자'출력됨