Program to remove all spaces from a string

Program to remove all spaces from a string

Input: skj ske se sw
Output: skjslesesw


removeSpaces.html


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Remove spaces from a string</title>
<script src="removeSpaces.js"></script>
</head>
<body>
<p>Enter text in the box with spaces: </p>
<input type="text" id="inputText" />
<button id="convertText" onclick="onConvertText()" >Convert</button>
<p id="convertedText"></p>
</body>
</html>



removeSpaces.js

function onConvertText() {
let inputText = document.getElementById('inputText').value.toString().replace(/ /g, '')
document.getElementById('convertedText').innerHTML = inputText;
}


Comments

Popular Posts