Endangered Species
Endangered Species
by Reddy Uppathi
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<ul data-continent="North America">
<li data-species="California condor">Critically Endangered</li>
<li data-species="American bison">Near Threatened</li>
</ul>
<ul data-continent="Europe">
<li data-species="Cave bear">Extinct</li>
</ul>
</div>
</body>
</html>
JavaScript
$(document).ready(function(){
var $continent = "";
var $spices = "";
$("ul").each(function(index, element){
var $this = $(this);
var $items = $this.find("li");
$continent = $(this).data("continent");
$spices = "";
var curerentSpice = ""
$.each($items, function(n, e)
{
//this is each li in this ul
$spices = $(this).data("species");
//curerentSpice = $(this).attr("data-species");
});
if($continent == "North America" && $spices == "American bison") {
var abc = endangeredSpecies($continent, $spices);
alert(abc)
}
});
function endangeredSpecies(continent, species) {
if(continent == "North America" && species == "American bison") {
curerentSpice = "Near Threatened"
return curerentSpice ;
}
}
});