Ask A.I. to write a "javascript console app" for you.
The program may contain various functions, but
It must "return" a value, to be displayed as a result.
This is the address of Google's Gemini A.I. chatbot.
<textarea id="code-input" rows="10" cols="50">
let name = "Developer Martin";
return "Hello, " + name + "!: " + calc(2,3);
function calc(x,y) {
let z = x+y;
return z;
}
</textarea>
<button onclick="runCode()">Run</button>
<p>Result: <span id="output"></span></p>
<script>
function runCode() {
const input = document.getElementById('code-input').value;
const outputElement = document.getElementById('output');
try {
// We wrap it in a function so we can use 'return' in the string
const userRoutine = new Function(input);
outputElement.innerText = userRoutine();
} catch (err) {
outputElement.innerText = "Error: " + err.message;
}
}
</script>