+ 1
[Javascript] Is it possible to nest method 'alert' into custom function?
function funcOutput (z, u) { this.z=z; this.u=u; var z = prompt ("Welcome! Please enter your name."); var u = prompt ("Thank you, "+z+"! Please, tell us. Are you our friend or enemy?") } Error: z is not defined. https://code.sololearn.com/WaQ66TA850ts/?ref=app
3 Antworten
+ 2
Seven Five You could override the build in alert with your own custom alert.
window.alert = function (message) {
return yourCustomAlert(message);
}
Check out the example
https://code.sololearn.com/WL62eN6G51Zr/?ref=app
+ 2
Seven Five if you are having problem of long code then just write
var z= prompt ("Welcome! please enter your name");
alert("Thank you:" + z+"please tell us. Are you our friend or enemy? )
+ 1
Alert is a method of Window object, right? Is it somehow connected with the error?
upd.: Thx for answers, custom alert sounds good. Does anyone knows if it's allowed to use alert method in function without custom alert?