new class js -advanced
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -40,6 +40,24 @@
|
||||
</main>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const outputEl = document.querySelector('.output');
|
||||
|
||||
const isPalindrom = (toCheckString) => {
|
||||
const reverseString = toCheckString
|
||||
.replace(/[$%!.,]/g, '')
|
||||
.split('')
|
||||
.reverse()
|
||||
.join('');
|
||||
return toCheckString.trim().toLowerCase() === reverseString.trim().toLowerCase() ? true : false;
|
||||
};
|
||||
|
||||
const toTest = ` Lagerregal`;
|
||||
|
||||
const result = isPalindrom(toTest);
|
||||
|
||||
console.log(toTest, result);
|
||||
outputEl.textContent = `${toTest} ist ${result ? 'ein' : 'KEIN'} Palindrom`;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user