dwiyanto dwiyanto - 1 year ago 57
Javascript Question

Insert new array and summing the results of the new array

I have a problem in my script. I tried to add value in the array if the same input with the list that I have, it will generate value array[score] 100 and if they included the same value then the [score] will increase, I still started to learn jquery.

var animal = ["duck", "cat", "dog", "bird", "frog", "horse"];
var list = "";
var score = [];

for (i = 0; i < animal.length; i++) {
list += animal[i] + ", ";
document.getElementById("data").innerHTML = list;

var $data = $("#target");
$('#add').click(function() {
if (this.value == animal){


list : <label id="data"></label>

<input id="target" class="form-control" type="text" value="">
<input id="submit" class="form-control" type="button" value="add">

score : <label id="count"></label>

Answer Source

Have created this fiddle based on your code, with these modifications:

  1. If the text entered in the input box matches an animal in the animal array, the score is increased by 100.
  2. The score is displayed in <label id="count"></label>
  3. The input box is cleared if the score is updated.

Is this what you wanted to achieve?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download