write simple javascript html css modal window
- User
write simple javascript html css modal window
- Assistant
Sure, here's a simple example of a modal window built using HTML, CSS, and JavaScript:
HTML:
<button id="openModal">Open Modal</button> <div id="overlay"></div> <div id="myModal"> <div id="modalContent"> <h2>This is a Modal Window</h2> <p>Click the Close button or outside of the Modal to close it.</p> <button id="closeModal">Close</button> </div> </div>CSS:
#overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); z-index: 1; } #myModal { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; padding: 20px; z-index: 2; } #myModal h2 { font-size: 1.5rem; margin-bottom: 10px; } #myModal p { margin-bottom: 20px; } #myModal button { background-color: #007bff; color: white; padding: 10px 20px; border: none; cursor: pointer; } #myModal button:hover { background-color: #0062cc; } #myModal button:focus { outline: none; } #closeModal { margin-top: 20px; } - User
write javascript function that generate has sums
- Assistant
Sure, here's an example of a JavaScript function that generates hash sums using the SHA-256 algorithm:
function generateHash(input) { const encoder = new TextEncoder(); const data = encoder.encode(input); return crypto.subtle.digest('SHA-256', data).then(hash => { let hexString = ''; const view = new DataView(hash); for (let i = 0; i < hash.byteLength; i += 4) { const value = view.getUint32(i); hexString += value.toString(16).padStart(8, '0'); } return hexString; }); }This function takes an input string as a parameter, encodes it using a TextEncoder, and then generates a hash using the SHA-256 algorithm using the
crypto.subtle.digest()method. The hash is returned as a Promise, which resolves to a hexadecimal string representation of the hash.To use this function, simply call it with an input string and handle the Promise returned by the function:
generateHash('hello world').then(hash => { console.log(hash); });This will output the hash of the input string "hello world" using the SHA-256 algorithm.
- User
write javascript function that generate string with random symbols
- Assistant
Sure, here's an example of a JavaScript function that generates a random string of symbols:
function generateRandomString(length) { const symbols = '!@#$%^&*()_-+={}[]|:;"<>,.?/~`'; let randomString = ''; for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * symbols.length); randomString += symbols.charAt(randomIndex); } return randomString; }This function takes a length parameter, which determines the length of the random string to be generated. It then defines a string of symbols to choose from and iterates through a loop for the specified length, randomly selecting a symbol from the symbols string and adding it to the randomString variable.
To use this function, simply call it with a desired length parameter:
const randomString = generateRandomString(10); console.log(randomString);This will output a random string of 10 symbols. You can adjust the length parameter to generate a string of any desired length.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.