Breaks with properties v2
by m4xout
HTML
<p id="demo"></p>
JavaScript
var swellDirection
var windDirection
var matchedBreaks = []
var breaks = [{
name:'Sandon Point',
swell: ['S','SE'],
wind: ['NW', 'W', 'SW']
},
{
name:'Bellambi',
swell: ['E', 'SE'],
wind: ['S', 'W', 'SW']
}
];
// Set the swell direction
swellDirection = prompt("What is the swell direction?" );
swellDirection = swellDirection.toUpperCase();
console.log('The swell direction has been set to ' + swellDirection);
// Set the wind direction
windDirection = prompt("What is the wind direction?" );
windDirection = windDirection.toUpperCase();
console.log('The wind direction has been set to ' + windDirection);
// Loop through breaks
for (var i in breaks) {
if (breaks.hasOwnProperty(i)) {
// Loop through swell directions within each break
for (var j in breaks[i].swell) {
if (breaks[i].swell[j].hasOwnProperty(j)) {
// Check if swell direction matches break
if (swellDirection == breaks[i].swell[j]) {
console.log('Swell matches with ' + breaks[i].name);
// Check if wind matches break
for (var k in breaks[i].wind) {
// Check if swell direction matches break
if (windDirection == breaks[i].wind[k]) {
console.log('Wind and swell matches with ' + breaks[i].name);
} else {
// console.log('We do not have a wind match with ' + breaks[i].name);
}
}
} else {
// console.log('We do not have a swell match with ' + breaks[i].name);
}
} else {
console.log('no no');
}
}
}
}
// Set the wind direction
//windDirection = prompt("What is the wind direction?" );
// Show input results
//alert('The swell direction is ' +...