I know there are a lot of topics for that but none of them answered my question.
I have to print lexicographically smallest and largest property in window. But I got the error Cannot set property of innerHTML of null at solve
.
Here is my html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Loops Homework</title>
<meta charset="UTF-8">
</head>
<body>
<span>Problem 1</span>
<button onclick="solve()">Print</button>
<div id="answer1">Answer will appear here</div>
<script src="LexicographicallyProp.js" type="text/javascript"></script>
</body>
</html>
And following javascript file:
function solve() {
let smallest = 'zzz',
largest = '',
prop,
div1 = document.getElementById('#answer1');
for (prop in document) {
if (prop < smallest) {
smallest = prop;
}
if (prop > largest) {
largest = prop;
}
}
div1.innerHTML = 'Smallest property in DOCUMENT: ' + smallest + ' ; Largest prop in DOCUMENT: ' + largest;
}