Skip to content

Commit fad9ea0

Browse files
committed
first commit
0 parents  commit fad9ea0

File tree

5 files changed

+158
-0
lines changed

5 files changed

+158
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Procedural Task List In Many Languages
2+
3+
## About
4+
5+
A task list application written in different languages with the purpose of comparing and contrasting them. It highlights very basic and high use statements in each language such as global and local variables, if else conditional statements, and while loops. It demonstrates how each language deals with: sending messages and gathering input from users, how to convert between strings and integers, define and call functions. I will continue to add more languages as I learn them... or submit them yourself through a pull request.
6+
7+
## Demos
8+
9+
1. JavaScript: open [index.html](index.html) in a browser.
10+
2. Python: from Terminal type $ `python task-list.py`.
11+
3. Ruby: from Terminal type $ `ruby task-list.rb`.
12+
13+
## Contributing
14+
15+
1. Fork me.
16+
2. Clone me.
17+
3. Submit a pull request.
18+
19+
## License
20+
21+
Copyright © 2016 Jonathan Grover, Purple Rabbit LLC, Code Pajamas
22+
23+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
24+
25+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="task-list.js"></script>

task-list.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var exit = false,
2+
tasks = [];
3+
4+
function display_tasks() {
5+
var num_tasks = tasks.length,
6+
response = "----------\n";
7+
for(i=0; i < num_tasks; i++) {
8+
response += (i+1) + ".) " + tasks[i] + "\n";
9+
}
10+
response += "\n----------";
11+
alert(response);
12+
}
13+
14+
function add_task() {
15+
var task = prompt("Type a new task:");
16+
tasks.push(task);
17+
display_tasks();
18+
}
19+
20+
function remove_task() {
21+
display_tasks();
22+
var index = parseInt(prompt("Type task number to remove:")) - 1;
23+
tasks.splice(index, 1);
24+
display_tasks();
25+
}
26+
27+
while (exit === false) {
28+
var choice = parseInt(prompt("Please enter a number from the following choices: 1. Insert a new task, 2. Remove a task, 3. List all tasks, 4. exit this program"));
29+
if (choice === 1) {
30+
add_task();
31+
}
32+
else if (choice === 2) {
33+
remove_task();
34+
}
35+
else if (choice === 3) {
36+
display_tasks();
37+
}
38+
else if (choice === 4) {
39+
alert("Exiting...");
40+
exit = true;
41+
window.close();
42+
}
43+
else {
44+
alert("sorry didn't recognize that input");
45+
}
46+
}

task-list.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
exit = False
2+
tasks = []
3+
4+
def display_tasks():
5+
num_tasks = len(tasks)
6+
i = 0
7+
print "----------"
8+
while (i < num_tasks):
9+
print str(i+1) + ".) " + tasks[i]
10+
i += 1
11+
print "----------"
12+
13+
def add_task():
14+
print "Type a new task:"
15+
task = raw_input()
16+
tasks.append(task)
17+
display_tasks()
18+
19+
def remove_task():
20+
display_tasks()
21+
print "Type task number to remove:"
22+
index = int(raw_input()) - 1
23+
tasks.pop(index)
24+
display_tasks()
25+
26+
while (exit == False):
27+
print "Please enter a number from the following choices: 1. Insert a new task, 2. Remove a task, 3. List all tasks, 4. exit this program"
28+
choice = int(raw_input())
29+
if (choice == 1):
30+
add_task()
31+
elif (choice == 2):
32+
remove_task()
33+
elif (choice == 3):
34+
display_tasks()
35+
elif (choice == 4):
36+
print "Exiting..."
37+
exit = True
38+
else:
39+
print "sorry didn't recognize that input"

task-list.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@exit = false
2+
@tasks = []
3+
4+
def display_tasks
5+
num_tasks = @tasks.length
6+
i = 0
7+
puts "----------"
8+
while i < num_tasks do
9+
puts "#{i+1}.) #{@tasks[i]}"
10+
i += 1
11+
end
12+
puts "----------"
13+
end
14+
15+
def add_task
16+
puts "Type a new task:"
17+
task = gets.chomp
18+
@tasks.push task
19+
display_tasks
20+
end
21+
22+
def remove_task
23+
display_tasks
24+
puts "Type task number to remove:"
25+
index = gets.chomp.to_i - 1
26+
@tasks.delete_at index
27+
display_tasks
28+
end
29+
30+
while @exit == false do
31+
puts "Please enter a number from the following choices: 1. Insert a new task, 2. Remove a task, 3. List all tasks, 4. exit this program"
32+
choice = gets.chomp.to_i
33+
if choice == 1
34+
add_task
35+
elsif choice == 2
36+
remove_task
37+
elsif choice == 3
38+
display_tasks
39+
elsif choice == 4
40+
puts "Exiting..."
41+
@exit = true
42+
else
43+
puts "sorry didn't recognize that input"
44+
end
45+
end

0 commit comments

Comments
 (0)