I tried to create an terminal like interface using javascript. (http://whois.ane.sh/terminal.html)
But I tried to call a function which I already created, it says undefined function.
This is my main logic of encode function And if I alert the final it works fine as expected but return is not returning the same value.
fetch('https://anish.vip/secure/encdec.php', {
method: 'POST',
body: formData
})
.then(response => response.text())
.then(data => {
let final = JSON.parse(data).final;
//alert(final);
return final;
})
.catch(error => {
return error;
});
Here's how the function is being called
if(keepValue.substring(0, 6) == 'encode' || keepValue.substring(0, 6) == 'decode'){
encode(keepValue)
.then(returnedValue => {
// Use the returned value in a subsequent part of your code
let systemOutput = returnedValue; // Assign the value
outputField[outputField.length - 1].innerHTML = systemOutput;
initialSection.innerHTML += "<br />" + initialPrompt;
})
}
I created an function encode. When user enters 'encode "message" pass' in the terminal, it is supposed to fetch data from my another php file and display the output. However it displayed undefined for my several attempts and after I did what chatgpt said, it says function undefined. Please help me out.