<!DOCTYPE html>
<html>
<head>
let postcode = 2100;
<script>
function getRegionFromPostcode(postcode) {
const regions = {
'Region Hovedstaden': ['1000-1799', '2000-2999', '3000-3699', '4000-4999', '5000-5999', '6000-6999', '7000-7999', '8000-9999'],
'Region Midtjylland': ['7000-7499', '8000-8999', '8600-8999', '8400-8599', '7800-8199', '7500-7799', '8300-8399', '8653-8654', '8700-8799', '8830-8831', '8850-8860', '8881-8883', '8900-8999'],
'Region Nordjylland': ['9000-9299', '9700-9999', '9300-9499', '9600-9699', '9800-9839'],
'Region Sjælland': ['4000-4999', '6000-6099', '6200-6499', '6600-6699', '4000-4299', '4600-4699', '4700-4760', '4771-4899', '4920-4999', '4100-4149', '4160-4299'],
'Region Syddanmark': ['5000-5999', '6000-6099', '6200-6499', '6500-6599', '6600-6699', '6700-6799', '7000-7169', '7171-7999', '7100-7149', '7200-7499', '7600-7799', '7800-8199', '8300-8389', '6000-6100']
};
for (const [region, postcodes] of Object.entries(regions)) {
for (const postcodeRange of postcodes) {
const [start, end] = postcodeRange.split('-').map(Number);
if (postcode >= start && postcode <= end) {
return region;
}
}
}
return 'Ukendt';
}
</script>
</head>
<body>
<h2>Demo JavaScript in Head</h2>
<p id="demo">A Paragraph.</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>