JavaScript Program to Change Text Color on Button Click

Write a JavaScript program to change text color on button click.



Source Code
<html>
<head>
    <title>Change Text Color on Button Click</title>
<script>
    function changeColor(color) {
        var x = document.getElementById("text");

        switch(color) {
            case 'red' : x.style.color = "red";
                break;
            case 'green' : x.style.color = "green";
                break;
            case 'blue' : x.style.color = "blue";
                break;
        }
    }
</script>
</head>
<body>
<p id="text">Click on button to change my color</p>
<input type="button" value="Red" onclick="changeColor('red')">
<input type="button" value="Green" onclick="changeColor('green')">
<input type="button" value="Blue" onclick="changeColor('blue')">
</body>
</html>
Output