html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html>
<head>
<title>Garland Words</title>
<meta name="description" content="Garland Words">
<meta name="author" content="cyk">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
</head>
<body>
<div id="garland">
<div id="actual_garland">
<p>Enter a word to check if it is a garland word:</p>
<form id="get_word_form">
<p><input type="text" placeholder="Your word" id="get_word" required autocomplete="off" onFocus="this.form.reset();"><input type="submit" value="SUBMIT"></p>
<p id="feedback">[The feedback will be here.]</p>
</form><br/>
<a href="https://www.sololearn.com/learn/7141/?ref=app">what is a garland word?</a>
</div>
</div>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
html, body {
width: 100%;
height: 100%;
margin: 0;
}
a:link{
color: SandyBrown;
font-weight: bold;
}
a:visited{
color: Purple;
}
a:active{
color: Salmon;
}
#garland{
position: relative;
vertical-align: center;
text-align: center;
width: 100%;
height: 100%;
background-color: PapayaWhip;
display: inline-table;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
jQuery(document).ready(function($){
$("#get_word_form").submit(function(event){
var word = $("#get_word").val();
var degree = isGarland(word);
if (degree !== -1)
$("#actual_garland").children("#get_word_form").children("#feedback").text('"' + word + '" is a garland word of degree ' + degree + '. The garland is "' + word.substring(0, degree).toLowerCase() + '".');
else
$("#actual_garland").children("#get_word_form").children("#feedback").text('"' + word + '" is not a garland word.');
event.preventDefault();
});
function isGarland(word){
word = word.toLowerCase();
var len = word.length, i = len - 1;
while (i >= 1){
if (word.substr(0, i) === word.substr(len - i, len))
return i;
i -= 1;
}
return -1;
}
});
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run