JSFiddle - React, Tailwind, and code Playground
by Alejandro
HTML
<p>Which fruits are in the array?</p>
<button>Bananas</button>
<button>Cherries</button>
<button>Grapes</button>
<button>Oranges</button>
<button>Peaches</button>
<button>Strawberries</button>
<p id="result"></p>
CSS
button {
display: block;
margin: 5px;
}
JavaScript
var fruits = ['Oranges', 'Cherries', 'Grapes'];
$('button').click(function () {
var fruit = $(this).text();
if ($.inArray(fruit, fruits) > -1) {
$('#result').html(fruit + ' are in the array!').css({ 'color': 'green' });
} else {
$('#result').html(fruit + ' are <strong>not</strong> in the array!').css({ 'color': 'red' });
}
});