Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Git Lab 1
# Nadula Gardiyehewa

## **<ins>RESOURCES</ins>**

- https://www.markdownguide.org/hacks/
- https://www.markdownguide.org/basic-syntax/
- https://www.geeksforgeeks.org/command-line-arguments-in-python/
- https://webaim.org/resources/contrastchecker/
Empty file added gitignore
Empty file.
46 changes: 46 additions & 0 deletions problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys

userInput = sys.argv[1:][0]

# INITIAL INPUT VALIDATION

if userInput[0] != '$':
print('[ERROR] Amount should start with dollar sign ($).')
sys.exit()

# SEPARATE DOLLARS AND CENTS
amount = userInput[1:]
dollars = amount.split('.')[0]
cents = amount.split('.')[1]

if len(dollars) == 0:
print('[ERROR] Dollars should have at least one digit.')
sys.exit()

if len(cents) != 2:
print('[ERROR] Cents should have 2 digits.')
sys.exit()

# PRINT THE RESULT
print(f'{dollars} dollars')

coins = ['quarter', 'dime', 'nickel', 'penny']
coins_plural = ['quarters', 'dimes', 'nickels', 'pennies']

cents = int(cents)

for i in range(4):
coinValue = 0
if i == 0:
coinValue = 25
elif i == 1:
coinValue = 10
elif i == 2:
coinValue = 5
else:
coinValue = 1

coinCount = cents // coinValue
cents = cents % coinValue
if coinCount > 0:
print(f'{coinCount} {coins[i] if coinCount == 1 else coins_plural[i]}')
31 changes: 31 additions & 0 deletions problem2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const userInput = process.argv.slice(2);

// INITIAL INPUT VALIDATION
if (userInput.length === 0) {
console.log("[ERROR] No input provided.");
process.exit();
}

// SANITIZE USER INPUT
let userInputSanitized = userInput
.join(" ")
.trim()
.replace(/\"/g, "")
.split(" ");

let userInputLower = userInputSanitized.map((word) => word.toLowerCase());

// FIND DUPLICATE WORDS
let words = new Map();

for (let word of userInputSanitized) {
if (
userInputLower.filter((w) => w === word.toLowerCase()).length > 1 &&
!words.has(word.toLowerCase())
) {
words.set(word.toLowerCase(), word);
}
}

// PRINT THE RESULT
words.forEach((word) => console.log(word));
21 changes: 21 additions & 0 deletions problem3.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
body,
html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #346094;
font-weight: 900;
font-size: 1.5rem;
}

form {
width: 80vw;
height: 70vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #8a8a8d;
}
26 changes: 26 additions & 0 deletions problem3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="problem3.css" />
</head>
<body>
<form>
<div>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required /><br />
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required /><br />
</div>
<div>
<label for="color">Favorite Color:</label>
<input type="color" id="color" name="color" required /><br />
</div>
<div>
<input type="submit" value="Submit" />
</div>
</form>
</body>
</html>