diff --git a/README.md b/README.md index 4fed924..ed8a00c 100644 --- a/README.md +++ b/README.md @@ -1 +1,8 @@ -# Git Lab 1 +# Nadula Gardiyehewa + +## **RESOURCES** + +- 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/ \ No newline at end of file diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..e69de29 diff --git a/problem1.py b/problem1.py new file mode 100644 index 0000000..61e2d07 --- /dev/null +++ b/problem1.py @@ -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]}') diff --git a/problem2.js b/problem2.js new file mode 100644 index 0000000..35ad8ce --- /dev/null +++ b/problem2.js @@ -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)); diff --git a/problem3.css b/problem3.css new file mode 100644 index 0000000..adfbdb2 --- /dev/null +++ b/problem3.css @@ -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; +} diff --git a/problem3.html b/problem3.html new file mode 100644 index 0000000..71d7654 --- /dev/null +++ b/problem3.html @@ -0,0 +1,26 @@ + + + + + + + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ +