Skip to content

Commit

Permalink
Fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
rodsejas committed Mar 11, 2022
2 parents 3c80221 + c4787b6 commit 6b1c61c
Show file tree
Hide file tree
Showing 124 changed files with 7,413 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Ai Bate/wk01 - starts 7th Mar/2-tue/functions/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<meta charset="utf-8">
<script src="js/exercises.js"></script>
</head>

<body>
<p>
Please check the Javascript console for output.
</p>
</body>
</html>
64 changes: 64 additions & 0 deletions Ai Bate/wk01 - starts 7th Mar/2-tue/functions/js/exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
console.log("it this thing on?");

// # The Calculator

// ## Part 1

// - Write a function called squareNumber that will take one argument (a number),

// square that number, and return the result. It should also log a string like "The result of squaring the number 3 is 9."
const squareNumber = function(number) {
let squareNumber = number*number;
console.log(`The result of squaring the number ${ number} is ${ squareNumber }`);
};
squareNumber(5);
// - Write a function called halfNumber that will take one argument (a number), divide it by 2,
// and return the result. It should also log a string like "Half of 5 is 2.5.".
const halfNumber = function(number) {
let halfNumber = number/2;
console.log(`Half of ${number} is ${halfNumber}.`);
};
halfNumber(10);

// - Write a function called percentOf that will take two numbers,
// figure out what percent the first number represents of the second number,
// and return the result. It should also log a string like "2 is 50% of 4."
const percentOf = function( numA, numB) {
let percent = numA/numB*100;
console.log(`${numA} is ${percent}% of ${numB}.`);
};
percentOf(100,50);

// - Write a function called areaOfCircle that will take one argument (the radius),
// calculate the area based on that, and return the result.
// It should also log a string like "The area for a circle with radius 2 is 12.566370614359172."
// - Bonus: Round the result so there are only two digits after the decimal.

const areaOfCircle = function(radius){
let areaOfCircle = Math.PI*radius*radius;
let roundedResult = areaOfCircle.toFixed(2);
console.log(`The area for a circle with radius ${radius} is ${roundedResult}.`);
};
areaOfCircle(10);





// ## Part 2

// Write a function that will take one argument (a number) and perform the following operations, using the functions you wrote earlier1:
// - Take half of the number and store the result.
// - Square the result of #1 and store that result.
// - Calculate the area of a circle with the result of #2 as the radius.
// - Calculate what percentage that area is of the squared result (#3).



const partTwoCalculator = function(x) {
let half = halfNumber(x);
let square = squareNumber(half);
let area = areaOfCircle(square);
let percentage = percentOf(square, area);
};
partTwoCalculator(500);
12 changes: 12 additions & 0 deletions Ai Bate/wk01 - starts 7th Mar/2-tue/strings/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<meta charset="utf-8">
<script src="js/exercises.js"></script>
</head>

<body>
<p>
Please check the Javascript console for output.
</p>
</body>
</html>
99 changes: 99 additions & 0 deletions Ai Bate/wk01 - starts 7th Mar/2-tue/strings/js/exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
console.log("it this thing on?");


// # Strings

// These exercises will test your knowledge of string functions, conditionals, and arrays. For many of them,
// you will want to consult the JavaScript strings reference to find useful string methods to call.

// ## DrEvil

// Create a function called DrEvil. It should take a single argument, an amount, and return '<amount> dollars',
// except it will add '(pinky)' at the end if the amount is 1 million. For example:
// ```
// DrEvil(10): 10 dollars
// DrEvil(1000000): 1000000 dollars (pinky)
// ```
const DrEvil = function(amount) {
if ( amount !==1000000){
console.log(`${ amount } dollars`);
} else {
console.log(`${ amount } dollars (pinky)`);
};
}
DrEvil(10);
DrEvil(1000000);



// ## MixUp

// Create a function called mixUp. It should take in two strings,
// and return the concatenation of the two strings (separated by a space) slicing out and swapping the first 2 characters of each.
// You can assume that the strings are at least 2 characters long. For example:
// ```
// mixUp('mix', 'pod'): 'pox mid'
// mixUp('dog', 'dinner'): 'dig donner'
// Look up the JavaScript string reference to find methods which may be useful!
// ```
const mixUp = function(a, b) {
let newWordA = b.slice(0, 2) + a.slice(2);
let newWordB = a.slice(0, 2) + b.slice(2);
console.log(`${newWordA} ${newWordB}`);
};
mixUp('dog','dinner');

// ## FixStart

// Create a function called fixStart. It should take a single argument, a string,
// and return a version where all occurences of its first character have been replaced with '*',
// except for the first character itself. You can assume that the string is at least one character long.
// For example:
// ```
// fixStart('babble'): 'ba**le'
// ```
const fixStart = function(x) {
let c = x.charAt(0);
let d = x.slice(1).replaceAll(c, "*")
console.log(`${c}${d}`);
};
fixStart('babble');
// ## Verbing

// Create a function called verbing. It should take a single argument, a string.
// If its length is at least 3, it should add 'ing' to its end, unless it already ends in 'ing',
// in which case it should add 'ly' instead. If the string length is less than 3, it should leave it unchanged. For example:
// ``
// verbing('swim'): 'swimming'
// verbing('swimming'): 'swimmingly'
// verbing('go'): 'go'
// ```
const verbing = function(word) {
if(word.length < 3){
console.log(word)
}else if(word.slice(-3) === "ing"){
const wordLy = word + "ly";
console.log(wordLy);
}else {
const wordIng = word + "ing";
console.log(wordIng);
}
};
verbing("swim");

// ## Not Bad

// Create a function called notBad that takes a single argument, a string.
// - It should find the first appearance of the substring 'not' and 'bad'.
// - If the 'bad' follows the 'not', then it should replace the whole 'not'...'bad' substring with 'good' and return the result.
// - If it doesn't find 'not' and 'bad' in the right sequence (or at all), just return the original sentence.

// For example:
// ```
// notBad('This dinner is not that bad!'): 'This dinner is good!'
// notBad('This movie is not so bad!'): 'This movie is good!'
// notBad('This dinner is bad!'): 'This dinner is bad!'
// ```
const notBad =function(wordB) {

}
10 changes: 10 additions & 0 deletions Ai Bate/wk01 - starts 7th Mar/3-wed/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta charset="utf-8">
<script src="js/exercise.js"></script>
</head>
<body>
<p>Please check the JS console for output.</p>
</body>
</html>

107 changes: 107 additions & 0 deletions Ai Bate/wk01 - starts 7th Mar/3-wed/js/exercise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
console.log("excise is here in console");


// # Array and Functions Bonus Material

// 1. Define a function `maxOfTwoNumbers` that takes two numbers as arguments and returns the largest of them.
// Use the if-then-else construct available in Javascript. You'll have to remember your pre-work, or do some googling to figure this out.
const maxOfTwoNumbers = function(n1,n2){
if( n1 > n2 ){
return (n1);
}else{
return (n2);
}

}
maxOfTwoNumbers(10,5); // testing
maxOfTwoNumbers(1,5);// testing
maxOfTwoNumbers(0,5);// testing
maxOfTwoNumbers(10,5);// testing
maxOfTwoNumbers(10,500);// testing
maxOfTwoNumbers(10,5);// testing


// 2. Define a function `maxOfThree` that takes three numbers as arguments and returns the largest of them.
const maxOfThree = function ( n3,n4,n5 ){
if( n3 >= n4 && n3 >= n5){
return n3;
} else if( n4 >= n3 && n4 >= n5) {
return n4;
} else {
return n5;
}
}
console.log(maxOfThree(10,20,30));
console.log(maxOfThree(20,10,30));
console.log(maxOfThree(20,30,30));
console.log(maxOfThree(10,20,20));
console.log(maxOfThree(30,20,10));
console.log(maxOfThree(10,10,20));

// 3. Write a function that takes a character (i.e. a string of length 1)
// and returns true if it is a vowel, false otherwise.
const vowelFinder = function(character) {
lowerCase = character.toLowerCase();
if(lowerCase === 'a' || lowerCase === 'e' || lowerCase === 'o'|| lowerCase === 'i'|| lowerCase ==='u' ) {
return true;
} else{
return false;
}
}
console.log(vowelFinder('a'));
console.log(vowelFinder('A'));
console.log(vowelFinder('B'));
console.log(vowelFinder('t'));

// 4. Define a function `sumArray` and a function `multiplyArray` that sums and multiplies
// (respectively) all the numbers in an array of numbers. For example, `sumArray([1,2,3,4])`
// should return 10, and `multiplyArray([1,2,3,4])` should return 24.
const sumArray = function(array){
let addTotal = 0;
for(let i = 0; i < array.length; i++ ){
addTotal += array[i];
}
return addTotal;
}
console.log(sumArray([1,2,3,4]));

const multiplyArray = function(array2){
let multiplyTotal=1
for(let i = 0; i < array2.length; i++ ){
multiplyTotal = multiplyTotal * array2[i]
}
return multiplyTotal;
}
console.log(multiplyArray([1,2,3,4]));


// ## Bonus

// 5. Define a function `reverseString` that computes the reversal of a string.

// For example, reverseString("jag testar") should return the string "ratset gaj".


const reverseString = function(sentence){
let reverseString ="";
for (let index = sentence.length-1; index>=0; index--) {
reverseString += sentence[index];
}
return reverseString;
}
console.log(reverseString("banana apple"));

// 6. Write a function `findLongestWord`
// that takes an array of words and returns the length of the longest one.
const findLongestWord = function(wordsList) {
let longestWord = "";
for( let i = 0; i< wordsList.length; i++){
if(wordsList[i].length > longestWord.length){
return longestWord;
}
}
}
findLongestWord('cat','milk', 'water', 'cucumber');
// console.log(findLongestWord(['cat','milk', 'water', 'cucumber']));
// 7. Write a function `filterLongWords` that takes an array of
// words and an number `i` and returns the array of words that are longer than i.å
14 changes: 14 additions & 0 deletions Alex Johnson/wk01 - starts 7th Mar/2-tue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="js/homework.js"></script>
<script src="js/homework01.js"s></script>
</head>
<bodjy>
<p>
Check the Javascript console for output.
</p>

</bodjy>
</html>
1 change: 1 addition & 0 deletions Alex Johnson/wk01 - starts 7th Mar/2-tue/js/homework.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("...Up and running...homework time");
Loading

0 comments on commit 6b1c61c

Please sign in to comment.