-
Notifications
You must be signed in to change notification settings - Fork 52
Day 1 assignment. #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SwathiUppu
wants to merge
2
commits into
sundarcodes:master
Choose a base branch
from
SwathiUppu:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script type="text/javascript" src="script.js"></script> | ||
<title>My App</title> | ||
</head> | ||
<body> | ||
<div> | ||
<h3>Factorial</h3> | ||
<p>Please enter number</p> | ||
<input type="text" id="factorial" /> | ||
<button onclick="factorial()"> Get Factorial</button> | ||
<p>Output:</p> | ||
<p id="getfactorial"></p> | ||
</div> | ||
<div> | ||
<h3>Sum of Natural Numbers</h3> | ||
<p>Please click</p> | ||
<button onclick="natural()"> Get Sum</button> | ||
<p>Output:</p> | ||
<p id="natural"></p> | ||
</div> | ||
<div> | ||
<h3>Power of 2</h3> | ||
<p>Please enter number</p> | ||
<input type="text" id="power" /> | ||
<button onclick="powerCheck()"> Get Value</button> | ||
<p>Output:</p> | ||
<p id="getpower"></p> | ||
</div> | ||
<div> | ||
<h3>Fizz Buzz</h3> | ||
<p>Please enter number</p> | ||
<input type="text" id="multiples" /> | ||
<button onclick="multiplesCheck()"> Get Value</button> | ||
<p>Output:</p> | ||
<p id="getmultiple"></p> | ||
</div> | ||
<div> | ||
<h3>Array Function</h3> | ||
<p>Find all pairs in [1, 4, 3, 5, 4, 6, 7, 8, 3] of integers whose sum is equal to 8.</p> | ||
<button onclick="arrayFunc()"> Get Value</button> | ||
<p>Output:</p> | ||
<p id="finalArray"></p> | ||
</div> | ||
<div> | ||
<h3>Array Repeat</h3> | ||
<p>Print all the numbers that are repeating in [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1]</p> | ||
<button onclick="arrayRepeat()"> Get Value</button> | ||
<p>Output:</p> | ||
<p id="finalArrayRepeat"></p> | ||
</div> | ||
<div> | ||
<h3>Object</h3> | ||
<p>Get amount paid in {"Rick": 85, "Amit": 42, "George": 53, "Tanya": 60, "Linda": 35}</p> | ||
<button onclick="amountPaid()"> Get Amount</button> | ||
<p>Output:</p> | ||
<p id="amount"></p> | ||
</div> | ||
<div> | ||
<h3>Palindrome</h3> | ||
<p>Please enter a string</p> | ||
<input type="text" id="palindrome" /> | ||
<button onclick="palindromeCheck()">Check if it is palindrome</button> | ||
<p>Output:</p> | ||
<p id="getpalindrome"></p> | ||
</div> | ||
<div> | ||
<h3>Palindrome in array</h3> | ||
<p>Please return palidrome in ["Malayalam", "tree", "boat", "civic", "melt", "level"]</p> | ||
<input type="text" id="palindromeArray" /> | ||
<button onclick="palindromeArray()">Get palindromes</button> | ||
<p>Output:</p> | ||
<p id="getpalindromeArray"></p> | ||
</div> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
var factorial = function() { | ||
var value = document.getElementById("factorial").value; | ||
var factorial = 1; | ||
for (var idx = 1; idx <= value; idx++) { | ||
factorial = factorial * idx; | ||
} | ||
document.getElementById("getfactorial").innerHTML = factorial; | ||
}; | ||
var natural = function() { | ||
var natural = 0; | ||
for (var idx = 1; idx <= 500; idx++) { | ||
natural = natural + idx; | ||
} | ||
document.getElementById("natural").innerHTML = natural; | ||
}; | ||
var naturalMultiples = function() { | ||
var naturalMultiple = 0; | ||
for (var idx = 1; idx < 1000; idx++) { | ||
if (idx % 3 === 0 || idx % 5 === 0) { | ||
naturalMultiple = naturalMultiple + idx; | ||
} | ||
} | ||
document.getElementById("naturalMultiple").innerHTML = naturalMultiple; | ||
}; | ||
var powerCheck = function() { | ||
var value = document.getElementById("power").value; | ||
var power; | ||
for (var idx = 1; idx <= value; idx++) { | ||
if (Math.pow(2, idx) <= value) { | ||
power = idx; | ||
} else { | ||
break; | ||
} | ||
} | ||
document.getElementById("getpower").innerHTML = power; | ||
}; | ||
var multiplesCheck = function() { | ||
var value = document.getElementById("multiples").value; | ||
var multiples = []; | ||
for (var idx = 1; idx <= value; idx++) { | ||
if (idx % 3 === 0) { | ||
multiples.push("Fizz"); | ||
} else if (idx % 5 === 0) { | ||
multiples.push("Buzz"); | ||
} else { | ||
multiples.push(idx); | ||
} | ||
} | ||
document.getElementById("getmultiple").innerHTML = multiples.join(" , "); | ||
}; | ||
var arrayFunc = function() { | ||
var array = [1, 4, 3, 5, 4, 6, 7, 8, 3]; | ||
var sum = 8; | ||
var finalArray = []; | ||
for (var i = 0; i <= array.length; i++) { | ||
for (var idx = i + 1; idx <= array.length; idx++) { | ||
if (array[i] + array[idx] === sum) { | ||
finalArray.push(array[i] + " , " + array[idx]); | ||
} | ||
} | ||
} | ||
document.getElementById("finalArray").innerHTML = finalArray.join("\r\n"); | ||
}; | ||
var arrayRepeat = function() { | ||
var array = [1, 2, 3, 5, 8, 4, 7, 9, 1, 4, 12, 5, 6, 5, 2, 1, 0, 8, 1, 12, 9]; | ||
var finalArray = []; | ||
for (var i = 0; i <= array.length; i++) { | ||
for (var idx = i + 1; idx <= array.length; idx++) { | ||
if (array[i] === array[idx] && finalArray.indexOf(array[i]) < 0) { | ||
finalArray.push(array[i]); | ||
} | ||
} | ||
} | ||
document.getElementById("finalArrayRepeat").innerHTML = finalArray.join(" , "); | ||
}; | ||
var amountPaid = function() { | ||
var amount = { | ||
"Rick": 85, | ||
"Amit": 42, | ||
"George": 53, | ||
"Tanya": 60, | ||
"Linda": 35 | ||
}; | ||
var amountPaid = 0; | ||
for (var idx in amount) { | ||
amountPaid = amountPaid + amount[idx]; | ||
} | ||
document.getElementById("amount").innerHTML = amountPaid; | ||
}; | ||
var palindromeCheck = function(palindromeValue) { | ||
var value = (palindromeValue) ? palindromeValue : document.getElementById("palindrome").value; | ||
var palindrome = value.split(""); | ||
if (value === palindrome.reverse().join("")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try to see if you avoid using reverse() and join() to achieve this ? |
||
(!palindromeValue) ? document.getElementById("getpalindrome").innerHTML = "It is a palindrome": ""; | ||
return true; | ||
} else { | ||
(!palindromeValue) ? document.getElementById("getpalindrome").innerHTML = "It is not a palindrome": ""; | ||
return false; | ||
} | ||
|
||
}; | ||
var palindromeArray = function() { | ||
var finalArray = []; | ||
var array = ["Malayalam", "tree", "boat", "civic", "melt", "level"]; | ||
for (var idx = 0; idx < array.length; idx++) { | ||
var a = array[idx].toLowerCase(); | ||
if (palindromeCheck(a)) { | ||
finalArray.push(array[idx]); | ||
} | ||
} | ||
document.getElementById("getpalindromeArray").innerHTML = finalArray.join(" , "); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try to see if you avoid 2 levels of looping ?