prompt js code example
Example 1: js prompt
var answer = prompt('What is your name?','Joe Blogg');
Example 2: javascript prompt
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}
Example 3: prompt js
var answer = prompt("How are you? ");
Example 4: how to get a user input in js
Copyvar name = window.prompt("Enter your name: ");
alert("Your name is " + name);
Example 5: react button onclick
import React, { Component } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.sayHello = this.sayHello.bind(this);
}
sayHello() {
alert('Hello!');
}
return (
<button onClick={this.sayHello}>
Click me!
</button>
);
}
export default App;