Breaks with properties v3
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']
},
{
name:'Cronulla',
swell: ['S', 'SE', 'E'],
wind: ['S', 'W', 'SW']
},
{
name:'East Corrimal',
swell: ['S', 'SE', 'E'],
wind: ['NW', 'N', 'NE', 'W']
},
{
name:'Garie Beach',
swell: ['S', 'SE'],
wind: ['NW', 'N', 'W']
},
{
name:'McCauleys',
swell: ['E', 'NE', 'SE'],
wind: ['NW', 'N', 'SW']
},
{
name:'North Era',
swell: ['S', 'SE'],
wind: ['NW', 'N', 'W']
},
{
name:'Port Kembla',
swell: ['S', 'SE'],
wind: ['NW', 'N', 'W']
},
{
name:'Sharkies',
swell: ['S', 'SE', 'E'],
wind: ['NW', 'SW', 'W']
},
{
name:'Stanwell Park',
swell: ['S', 'SE'],
wind: ['NW', 'N', 'W']
},
{
name:'Thirroul',
swell: ['E', 'SE', 'NE'],
wind: ['NW', 'SW', 'W']
},
{
name:'Werri Beach',
swell: ['E', 'S', 'SE'],
wind: ['NW', 'N', 'W', 'SW']
},
{
name:'Wombarra',
swell: ['E', 'NE', 'SE'],
wind: ['NW', '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...