<header>
  <h2 class="title">String.prototype.slice()</h2>
  <p class="description">Вирізає підрядок з основного рядка, використовуючи початковий та кінцевий індекси.</p>
</header>
<main>
  <div class="result">
    <input type="text" id="inputText" placeholder="Введіть рядок" />
    <input type="number" id="startIndex" placeholder="Початковий індекс" />
    <input type="number" id="endIndex" placeholder="Кінцевий індекс" />
    <button onclick="sliceText()">Вирізати</button>
    <p id="output">Вирізаний рядок: </p>
  </div>
</main>
body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  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;
}

.result {
  background-color: #f8f8f8;
  padding: 15px;
  -webkit-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  -moz-box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

input[type="text"], input[type="number"] {
  margin: 10px 0;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  padding: 10px 15px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #45a049;
}

#output {
  margin-top: 15px;
  font-weight: bold;
}
function sliceText() {
  var text = document.getElementById('inputText').value;
  var start = parseInt(document.getElementById('startIndex').value);
  var end = parseInt(document.getElementById('endIndex').value);
  var slicedText = text.slice(start, end);
  document.getElementById('output').innerHTML = 'Вирізаний рядок: ' + slicedText;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.