JSFiddle - React, Tailwind, and code Playground

by moojjoo

HTML

<body>
    <p>Click the button to demonstrate the prompt box.</p>
    <button onclick="myFunction()">Try it</button>
    <button onclick="calcArea()">Calculate Area of Circle</button>
    <p id="demo"></p>
    
    <p id="arrayValue"></p>
</body>

JavaScript

function myFunction() {
    var testCase;
    var firstLetter;

    testCase = prompt("Type a word");

    firstLetter = testCase.charAt(0).toLowerCase();

    if (firstLetter === 'a') {
        document.getElementById("demo").innerHTML = testCase + " starts with 'A'";
    } else if (firstLetter === 'z') {
        document.getElementById("demo").innerHTML = testCase + " starts with 'Z'";
    } else {
        document.getElementById("demo").innerHTML = testCase + " does not start with either 'A' or 'Z'";
    }
    //alert('Hello World');
    return;
}


function calcArea(){
 	var radius = prompt("What radius do you want to use to calculate the area of a circle?"); 
    
    var area = radius * radius * 3.14159;
    document.getElementById("demo").innerHTML = "The area of the circle is " + area;    
}


var myArray = [5, 10, 20];

for(var i = 0; i < myArray.length; i++){
    var totalValue = myArray[i] + totalValue;
    
    }
    
    document.getElementById("arrayValue").innerHTML = totalValue;