ShowInfo : function (number) {
var answer
App.contracts.StudentState.deployed().then(function (instance) {
return instance.showFName(number);
}).then(function (Cert) {
answer = Cert;
})
console.log(answer);
return answer;
},
Here is the function I have been trying to perfect for too much time then I should. I am new to JavaScript and need for this function to return a variable called answer, but I always get it as undefined, I know that in JavaScript I just can't have global variables that easily, but how do I fix this code? This is linked with Ethereum smart contracts from where I receive a number.
Thank you for your time and effort.
Well these are the two code lines I'm using at the moment:
var wrapper = document.getElementById("myHTMLWrapper");
var myHTML = '';
for (var i = 0; i < num; i++) {
var ans = App.ShowInfo(i);
myHTML += '<span class="test">INFO:' + ans + '</span><br/><br/>';
}
wrapper.innerHTML = myHTML
ShowInfo : function (number) {
var answer = App.contracts.StudentState.deployed().then(function (instance) {
return instance.showFName(number);
})
console.log(answer);
return answer;
},