-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathpalindrome.html
More file actions
84 lines (81 loc) · 3.85 KB
/
palindrome.html
File metadata and controls
84 lines (81 loc) · 3.85 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>Palindrome</title>
<script src="/bjc-r/llab/loader.js"></script>
<link href="/bjc-r/js-parsons/parsons.css" rel="stylesheet" />
<link href="/bjc-r/js-parsons/lib/prettify.css" rel="stylesheet" />
<script src="/bjc-r/js-parsons/lib/prettify.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-176402054-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-176402054-1');
</script>
</head>
<body>
<h2>Exercise 3: Palindrome</h2>
<p>Drag and drop the code below to write a function <code>palindrome(string)</code>, which should return <code>True</code> if the input string is a palindrome and <code>False</code> otherwise. </p>
<p>You can reorder the blocks and drag them to different indentation levels as you wish. You may not need to use all of the provided lines. </p>
<div id="sortableTrash" class="sortable-code"></div>
<div id="sortable" class="sortable-code">
</div>
<div style="clear:both;"></div>
<p style="text-align: center">
<a class="parsonsButton" href="#" id="feedbackLink">Get feedback</a>
<a class="parsonsButton" class="parsonsButton" href="#" id="exportLink">Export</a>
</p>
<p class="alert alert-danger quoteRed">
Before you leave this page, be sure to check your answer for correctness by clicking "Get feedback" above and export your code using the "Export button." <strong>You will need to show your exported code to get credit for this lab.</strong>
</p>
<script src="/bjc-r/js-parsons/lib/jquery.min.js"></script>
<script src="/bjc-r/js-parsons/lib/jquery-ui.min.js"></script>
<script src="/bjc-r/js-parsons/lib/jquery.ui.touch-punch.min.js"></script>
<script src="/bjc-r/js-parsons/lib/underscore-min.js"></script>
<script src="/bjc-r/js-parsons/lib/lis.js"></script>
<script src="/bjc-r/js-parsons/parsons.js"></script>
<script>
var initial = 'def palindrome(string):\n' +
' if len(string) < 2:\n' +
' if len(string) < 2 #distractor\n' +
' return True\n' +
' return False #distractor\n' +
' elif string[0] != string[-1]:\n' +
' elif string[0] != string[1]: #distractor\n' +
' return False\n' +
' return palindrome(string[1:-1])\n' +
' return palindrome(string[0:-1]) #distractor\n' +
' return palindrome(string[1:-2]) #distractor\n' +
' return palindrome(string[0:-2]) #distractor\n'
function displayErrors(fb) {
if(fb.errors.length > 0) {
alert(fb.errors[0]);
}
}
$$(document).ready(function(){
var parson = new ParsonsWidget({
'sortableId': 'sortable',
'trashId': 'sortableTrash',
'max_wrong_lines': 4,
'feedback_cb' : displayErrors
});
parson.init(initial);
parson.shuffleLines();
$$("#newInstanceLink").click(function(event){
event.preventDefault();
parson.shuffleLines();
});
$$("#feedbackLink").click(function(event){
event.preventDefault();
parson.getFeedback("palindrome");
});
$$("#exportLink").click(function(event){
event.preventDefault();
parson.export("palindrome.py");
});
});
</script>
</body>
</html>