TODO: Write a project description
TODO: Describe the installation process
var userChoice = ""; | |
do | |
{ | |
var targetNumber = Number(prompt("Please enter your target number", "")); | |
var start = 0; | |
while (start <= targetNumber) | |
{ | |
document.write(start + "<br/>"); | |
start = start + 2; | |
} |
var swapCase = function(string){ | |
var newString = " "; | |
for(var i = 0; i< string.length; i++){ | |
if(string[i] === string[i].toLowerCase()){ | |
newString += string[i].toUpperCase(); | |
}else { | |
newString += string[i].toLowerCase(); | |
} | |
} | |
console.log(newString); |
function triangular(N) { | |
var total = 0; | |
for(var i = 1; i <= N; i++){ | |
total += i; | |
} | |
return total; | |
} | |
console.log(triangular(100)); | |
//5050 |
/*Recursion | |
We’ve seen that % (the remainder operator) can be used to test whether a number | |
is even or odd by using % 2 to check whether it’s divisible by two. | |
Here’s another way to define whether a positive whole number is even or odd: | |
Zero is even. | |
One is odd. | |
For any other number N, its evenness is the same as N - 2. | |
Define a recursive function isEven corresponding to this description. | |
The function should accept a number parameter and return a Boolean. | |
Test it on 50 and 75. See how it behaves on -1. Why? Can you think of a way to fix this? |
//www.lsauer.com 2012 | |
//Answer to: | |
//http://stackoverflow.com/questions/881085/count-the-number-of-occurances-of-a-character-in-a-string-in-javascript/10671743#10671743 | |
//There are at least four ways. The best option, which should also be the fastest -owing to the native RegEx engine -, is placed at the top. //jsperf.com is currently down, otherwise I would provide you with performance statistics. | |
#1. | |
("this is foo bar".match(/o/g)||[]).length | |
//>2 | |
#2. | |
"this is foo bar".split("o").length-1 |
/*You can get the Nth character, or letter, from a string by writing "string".charAt(N) | |
similar to how you get its length with "s".length. | |
The returned value will be a string containing only one character (for example, "b"). | |
The first character has position zero, which causes the last one to be found at position string.length - 1. | |
In other words, a two-character string has length 2, and its characters have positions 0 and 1. | |
Write a function countBs that takes a string as its only argument | |
Returns a number that indicates how many uppercase “B” characters are in the string. | |
Next, write a function called countChar that behaves like countBs, | |
except it takes a second argument that indicates the character that is to be counted | |
(rather than counting only uppercase “B” characters). Rewrite countBs to make use of this new function. |
<div class='search'> | |
<input type="text" id='query' required></input> | |
<button id='search'>Search</button> | |
</div> | |
<div class="movieOptions"> | |
<button class="categories" onclick="topMovies()">Top Movies</button> | |
<button class="categories" onclick="popular()">Popular</button> | |
<button class="categories" onclick="nowPlaying()"> Now Playing </button> | |
<button class="categories" onclick="upcoming()"> Upcoming </button> | |
<button class="categories" onclick="tvPopular()"> TV Popular </button> |
// takes the form field value and returns true on valid number | |
function valid_credit_card(value) { | |
// accept only digits, dashes or spaces | |
if (/[^0-9-\s]+/.test(value)) return false; | |
// The Luhn Algorithm. It's so pretty. | |
var nCheck = 0, nDigit = 0, bEven = false; | |
value = value.replace(/\D/g, ""); | |
for (var n = value.length - 1; n >= 0; n--) { |
//Source: https://stackoverflow.com/questions/33232823/javascript-compare-two-objects-and-get-key-value-pair | |
// compare objects with symmetrical keys | |
function diffObject(a, b) { | |
return Object.keys(a).reduce(function(map, k) { | |
if (a[k] !== b[k]) map[k] = b[k]; | |
return map; | |
}, {}); | |
} | |
console.log(diffObject({A: 10, B: 20, C: 30}, {A: 10, B: 22, C: 30})); |