Week 4 Task 7
Write a function that converts a string for the day of the week into a number. For example, the function should return 0 for the string “Monday” and return 6 for the string “Sunday. Return -1 if the string is not a valid day of the week. HINT: See the Array indexOf() method at http://www.w3schools.com/jsref/jsref_indexof_array.asp
by Ken Wai Ooi
HTML
<p>Click the button to display the position of the element "Monday":</p>
<button onclick="myFunction()">Convert Day into String</button>
<p id="demo"></p>
<script>
function myFunction() {
var weeks = ["Monday", "Tuesday", "Wednesday", "Thursday","Friday","Saturday","Sunday"];
var a = weeks.indexOf("Monday");
document.getElementById("demo").innerHTML = a;
}
</script>