আমাদের একটি জাভাস্ক্রিপ্ট প্রোগ্রাম লিখতে হবে যা ইউজারকে একটি স্ট্রিং ভ্যালু ইনপুট দিতে 데বে।
প্রোগ্রামটি ইনপুট ভ্যালুটিকে কিছু হার্ড-কোডেড অ্যারে ভ্যালুর সাথে চেক করবে। যদি ইনপুট স্ট্রিং অ্যারেতে থাকে তবে প্রোগ্রামটি স্ক্রিনে true প্রিন্ট করবে, অন্যথায় false।
উদাহরণ
কোডটি হবে:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>CHECK EXISTENCE</title>
</head>
<body>
<script>
const arr = ['arsenal', 'chelsea', 'everton', 'fulham',
'swansea'];
const checkExistence = () => {
const userInput = document.getElementById("input").value;
const exists = arr.includes(userInput);
document.getElementById('result').innerText = exists;
};
</script>
<input type="text" id="input">
<button onclick="checkExistence()">Check</button>
<p id='result'></p>
</body>
</html>
আউটপুট
স্ক্রিনে আউটপুট হবে:
