There are several built-in functions to interact with the user:
alert('Text message');
prompt('What is your name?');
confirm('Do you want to learn JavaScript')
Function
alert
shows a text message
alert('Text message');
Function
prompt
asks the user to input a text. It can be an answer for the question that the function asks the user
prompt('What is your name?');
The function has another optional parameter, which is a default value of the input
prompt('What is your favorite programming language?', 'JavaScript');
Function
confirm
asks the user and waits for the user to accept or cancel
confirm('Do you want to learn JavaScript')
Simple example of the three interactive functions together:
if (confirm('Do you want to learn programming?')) {
    let language = prompt('Choose your favorite programming language: JS, Python, PHP', 'JS');
    alert('You will be redirected to ' + language + " tutorial's page");
    window.location.href = 'https://w3schools.com/'+language;
} else {
    alert('Go waste your time with playing video games')
}
by Valeri Tandilashvili
4 years ago
JavaScript
Built-in functions
1
Pro tip: use ```triple backticks around text``` to write in code fences
0
Giorgi Ivanidze 4 years ago
chemi magalitia bolo example-shi :D
REPLY
Show 1 reply