Array Includes()

Untuk Latihan nomor 2 Maksudnya seperti apa ya?

function checkFood(foodName) {

const isNotEmptyString = (foodName !== " ")

const foodIsIncluded = foods.includes(foodName)

if(isNotEmptyString && foodIsIncluded) {

    console.log("Makanan sudah tersedia")

    console.log(foods)

} else {

    foods.push(foodName)

    console.log(foods)

}

}

checkFood(“Kwetiaw”)

2 Likes

terimakasih kak, sudah berhasil

const foods = [‘siomay’, ‘dimsum’, ‘gyoza’, ‘pangsit’];

// Buat kode kamu di bawah ini

function checkFood (foodName) {

let isNotEmptyString = foodName !== “” ? true : false;

let foodIsIncluded = foods.includes(foodName);

console.log(isNotEmptyString, foodIsIncluded)

if(isNotEmptyString && foodIsIncluded) {

   console.log("makanan sudah terserida " + foods);

} else {

   foods.push(foodName);

   console.log(foods)

}

}

checkFood(“Kwetiaw”)


Kak Saya Mencoba copy paste pogram kak tapi di saya malah error solusisnya bagaimna kak ?