<header>
<h2 class="title">String.prototype.at()</h2>
<p class="description">Повертає символ за зазначеним індексом, з можливістю використання від'ємних індексів для пошуку з кінця рядка.</p>
</header>
<main>
<div class="input-section">
<label for="inputString">Введіть рядок: </label>
<input type="text" id="inputString" placeholder="Привіт, світ!">
<br><br>
<label for="inputIndex">Введіть індекс: </label>
<input type="number" id="inputIndex" placeholder="наприклад, 7 або -1">
<button id="getChar">Отримати символ</button>
</div>
<div class="result">
<p>Символ за індексом: <span id="outputChar">-</span></p>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.input-section {
margin-bottom: 15px;
}
.input-section label {
margin-right: 10px;
}
.input-section input {
margin-right: 10px;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
margin-top: 15px;
}
.result p {
margin: 0;
font-weight: bold;
}
button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
document.getElementById('getChar').addEventListener('click', function() {
const inputString = document.getElementById('inputString').value;
const inputIndex = parseInt(document.getElementById('inputIndex').value, 10);
const outputChar = inputString.at(inputIndex);
document.getElementById('outputChar').textContent = outputChar || 'немає символу';
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.