+ 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

1st Mar 2019, 8:14 AM
Seven Five
Seven Five - avatar
3 Respostas
+ 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
1st Mar 2019, 9:03 AM
Calviղ
Calviղ - avatar
+ 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? )
1st Mar 2019, 8:33 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 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?
1st Mar 2019, 8:20 AM
Seven Five
Seven Five - avatar