diff --git a/index.js b/index.js index 9c463fba0..92283fd96 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,10 @@ Do the following: HINT: no function required */ +const votingAge = 18; +if (votingAge >= 18) { + console.log(true); +}; @@ -31,6 +35,14 @@ Do the following: HINT: no function required */ +let a = 2; +let b = 3; + +if (a = 2) { + b = 2; + console.log(b); +} + @@ -46,7 +58,8 @@ Do the following: HINT: look up the Number method */ - +const year = '1999'; +console.log(Number(year)); /* @@ -58,9 +71,12 @@ Do the following: 3. Multiply a and b and return the answer */ -function multiply(/*add your code here*/){ - /*add your code here*/ - } +function multiply(a, b) { + /*add your code here*/ + return a * b; +} + +multiply(5, 3); @@ -74,10 +90,13 @@ Do the following: 3. Return the newly calculated age */ -function dogYears(/*add your code here*/){ - /*add your code here*/ +function dogYears(a) { + /*add your code here*/ + return a * 7; } +dogYears(5); + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -105,11 +124,26 @@ Use the hungryDog function and feeding requirements below to do the following: 7 - 12 months 4% of their body weight NOTE: If done correctly, a weight of 15 lbs and age of 1 year would return 0.44999999999999996 -*/ +*/ -function hungryDog(/*add your code here*/){ - /*add your code here*/ +function hungryDog(pounds, years) { + /*add your code here*/ + if (years >= 1 && pounds <= 5) { + return pounds * .05; + } else if (years >= 1 && pounds > 5 && pounds <= 10) { + return pounds * .04; + } else if (years >= 1 && pounds > 10 && pounds <= 15) { + return pounds * .03; + } else if (years >= .17 && years <= .33) { + return pounds * .10; + } else if (years >= .33 && years <= .59) { + return pounds * .5; + } else if (years >= .59 && years <= 1) { + return pounds * .4; } +} + +console.log(hungryDog(15, 1)) @@ -134,11 +168,38 @@ Use the game function below to do the following: HINT: Remember that the order in which we pass in our arguments matters when it comes to parameters */ -function game(user, computer){ - /*add your code here*/ +const rock = 0; +const paper = 1; +const scissors = 2; +let genComputerChoice = max => { + return Math.floor(Math.random() * max) +}; + +function game(userChoice) { + let computerChoice = genComputerChoice(3); + console.log(computerChoice); + if (userChoice === "rock" && computerChoice === rock) { + return "it's a tie!"; + } else if (userChoice === "paper" && computerChoice === paper) { + return "it's a tie"; + } else if (userChoice === "scissors" && computerChoice === scissors) { + return "it's a tie"; + } else if (userChoice === "rock" && computerChoice === scissors) { + return "you win!"; + } else if (userChoice === "rock" && computerChoice === paper) { + return "you lose!"; + } else if (userChoice === "paper" && computerChoice === scissors) { + return "you lose!"; + } else if (userChoice === "paper" && computerChoice === rock) { + return "you win!" + } else if (userChoice === "scissors" && computerChoice === paper) { + return "you win!"; + } else if (userChoice === "scissors" && computerChoice === rock) { + return "you lose"; + } } - - + + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -151,9 +212,9 @@ Using the miles function below do the following: 3. Return the number of miles */ -function miles(/*add your code here*/){ - /*add your code here*/ - } +function miles(kilometers) { + return kilometers * .62137; +} @@ -165,10 +226,10 @@ Using the feet function below do the following: 3. Return number of feet */ -function feet(/*add your code here*/){ - /*add your code here*/ - } - +function feet(cm) { + return cm / 30.48; +} + /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -181,9 +242,12 @@ Using the annoyingSong function below do the following: "{number} bottles of soda on the wall, {number} bottles of soda, take one down pass it around {number left over} bottles of soda on the wall" */ -function annoyingSong(/*add your code here*/){ - /*add your code here*/ +function annoyingSong(numberBottles) { + /*add your code here*/ + for (let i = 0; i < numberBottles; i++) { + return `${numberBottles} bottles of soda on the wall, ${numberBottles} bottles of soda, take one down pass it around ${numberBottles - 1} bottles of soda on the wall`; } +} /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀*/ @@ -200,12 +264,22 @@ Using the grade function below do the following: 60-69 should return 'you got a D' below should return 'you got an F' */ - -function grade(/*Your Code here */){ - /*Your Code here */ + +function grade(score) { + if (score >= 90 && score <= 100) { + return "you got an A"; + } else if (score >= 80 && score <= 89) { + return "you got a B" + } else if (score >= 70 && score <= 79) { + return "you got a C"; + } else if (score >= 60 && score <= 69) { + return "you got a D"; + } else { + return "you got an F"; } - - +}; + + /*💪💪💪💪💪💪💪💪💪💪 Stretch 💪💪💪💪💪💪💪💪💪💪*/ @@ -220,26 +294,26 @@ Using the vowelCounter function below do the following: */ -function vowelCounter(/*add your code here*/) { - /*add your code here*/ +function vowelCounter( /*add your code here*/ ) { + /*add your code here*/ } /*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/ -function foo(){ - //console.log('its working'); - return 'bar'; +function foo() { + //console.log('its working'); + return 'bar'; } /*🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Don't touch the code after this line! 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑*/ -export default{ - foo, - multiply, - dogYears, - hungryDog, - game, - miles, - feet, - annoyingSong, - grade -} +export default { + foo, + multiply, + dogYears, + hungryDog, + game, + miles, + feet, + annoyingSong, + grade +} \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index 7e4c1d94e..e17a96d31 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,190 +3,190 @@ module.exports = { // All imported modules in your tests should be mocked automatically - // automock: false, + automock: false, // Stop running tests after `n` failures - // bail: 0, + bail: 0, // The directory where Jest should store its cached dependency information - // cacheDirectory: "/private/var/folders/sv/ddl5gf4s2yb4mr4tbt5v6hx00000gn/T/jest_dx", + cacheDirectory: "/private/var/folders/sv/ddl5gf4s2yb4mr4tbt5v6hx00000gn/T/jest_dx", // Automatically clear mock calls and instances between every test - // clearMocks: false, + clearMocks: false, // Indicates whether the coverage information should be collected while executing the test - // collectCoverage: false, + collectCoverage: false, // An array of glob patterns indicating a set of files for which coverage information should be collected - // collectCoverageFrom: undefined, + collectCoverageFrom: undefined, // The directory where Jest should output its coverage files - // coverageDirectory: undefined, + coverageDirectory: undefined, // An array of regexp pattern strings used to skip coverage collection - // coveragePathIgnorePatterns: [ - // "/node_modules/" - // ], + coveragePathIgnorePatterns: [ + "/node_modules/" + ], // Indicates which provider should be used to instrument code for coverage - // coverageProvider: "babel", + coverageProvider: "babel", // A list of reporter names that Jest uses when writing coverage reports - // coverageReporters: [ - // "json", - // "text", - // "lcov", - // "clover" - // ], + coverageReporters: [ + "json", + "text", + "lcov", + "clover" + ], // An object that configures minimum threshold enforcement for coverage results - // coverageThreshold: undefined, + coverageThreshold: undefined, // A path to a custom dependency extractor - // dependencyExtractor: undefined, + dependencyExtractor: undefined, // Make calling deprecated APIs throw helpful error messages - // errorOnDeprecated: false, + errorOnDeprecated: false, // Force coverage collection from ignored files using an array of glob patterns - // forceCoverageMatch: [], + forceCoverageMatch: [], // A path to a module which exports an async function that is triggered once before all test suites - // globalSetup: undefined, + globalSetup: undefined, // A path to a module which exports an async function that is triggered once after all test suites - // globalTeardown: undefined, + globalTeardown: undefined, // A set of global variables that need to be available in all test environments - // globals: {}, + globals: {}, // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. - // maxWorkers: "50%", + maxWorkers: "50%", // An array of directory names to be searched recursively up from the requiring module's location - // moduleDirectories: [ - // "node_modules" - // ], + moduleDirectories: [ + "node_modules" + ], // An array of file extensions your modules use - // moduleFileExtensions: [ - // "js", - // "json", - // "jsx", - // "ts", - // "tsx", - // "node" - // ], + moduleFileExtensions: [ + "js", + "json", + "jsx", + "ts", + "tsx", + "node" + ], // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module - // moduleNameMapper: {}, + moduleNameMapper: {}, // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader - // modulePathIgnorePatterns: [], + modulePathIgnorePatterns: [], // Activates notifications for test results - // notify: false, + notify: false, // An enum that specifies notification mode. Requires { notify: true } - // notifyMode: "failure-change", + notifyMode: "failure-change", // A preset that is used as a base for Jest's configuration - // preset: undefined, + preset: undefined, // Run tests from one or more projects - // projects: undefined, + projects: undefined, // Use this configuration option to add custom reporters to Jest - // reporters: undefined, + reporters: undefined, // Automatically reset mock state between every test - // resetMocks: false, + resetMocks: false, // Reset the module registry before running each individual test - // resetModules: false, + resetModules: false, // A path to a custom resolver - // resolver: undefined, + resolver: undefined, // Automatically restore mock state between every test - // restoreMocks: false, + restoreMocks: false, // The root directory that Jest should scan for tests and modules within - // rootDir: undefined, + rootDir: undefined, // A list of paths to directories that Jest should use to search for files in - // roots: [ - // "" - // ], + roots: [ + "" + ], // Allows you to use a custom runner instead of Jest's default test runner - // runner: "jest-runner", + runner: "jest-runner", // The paths to modules that run some code to configure or set up the testing environment before each test - // setupFiles: [], + setupFiles: [], // A list of paths to modules that run some code to configure or set up the testing framework before each test - // setupFilesAfterEnv: [], + setupFilesAfterEnv: [], // The number of seconds after which a test is considered as slow and reported as such in the results. - // slowTestThreshold: 5, + slowTestThreshold: 5, // A list of paths to snapshot serializer modules Jest should use for snapshot testing - // snapshotSerializers: [], + snapshotSerializers: [], // The test environment that will be used for testing testEnvironment: "node", // Options that will be passed to the testEnvironment - // testEnvironmentOptions: {}, + testEnvironmentOptions: {}, // Adds a location field to test results - // testLocationInResults: false, + testLocationInResults: false, // The glob patterns Jest uses to detect test files - // testMatch: [ - // "**/__tests__/**/*.[jt]s?(x)", - // "**/?(*.)+(spec|test).[tj]s?(x)" - // ], + testMatch: [ + "**/__tests__/**/*.[jt]s?(x)", + "**/?(*.)+(spec|test).[tj]s?(x)" + ], // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped - // testPathIgnorePatterns: [ - // "/node_modules/" - // ], + testPathIgnorePatterns: [ + "/node_modules/" + ], // The regexp pattern or array of patterns that Jest uses to detect test files - // testRegex: [], + testRegex: [], // This option allows the use of a custom results processor - // testResultsProcessor: undefined, + testResultsProcessor: undefined, // This option allows use of a custom test runner - // testRunner: "jasmine2", + testRunner: "jasmine2", // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href - // testURL: "http://localhost", + testURL: "http://localhost", // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" - // timers: "real", + timers: "real", // A map from regular expressions to paths to transformers - // transform: undefined, + transform: undefined, // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation - // transformIgnorePatterns: [ - // "/node_modules/", - // "\\.pnp\\.[^\\/]+$" - // ], + transformIgnorePatterns: [ + "/node_modules/", + "\\.pnp\\.[^\\/]+$" + ], // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them - // unmockedModulePathPatterns: undefined, + unmockedModulePathPatterns: undefined, // Indicates whether each individual test should be reported during the run - // verbose: undefined, + verbose: undefined, // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode - // watchPathIgnorePatterns: [], + watchPathIgnorePatterns: [], // Whether to use watchman for file crawling - // watchman: true, -}; + watchman: true, +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c901c74a8..493fd6597 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4452,6 +4452,19 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "node": { + "version": "15.12.0", + "resolved": "https://registry.npmjs.org/node/-/node-15.12.0.tgz", + "integrity": "sha512-0R4LdnFQzII7I04A2eY1d4TypvH6XhSMluRr477Zwz43jUWdM+bayWsLfgnkf1Cv4Tbl9MaTAjAIvGpC0+6gFQ==", + "requires": { + "node-bin-setup": "^1.0.0" + } + }, + "node-bin-setup": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/node-bin-setup/-/node-bin-setup-1.0.6.tgz", + "integrity": "sha512-uPIxXNis1CRbv1DwqAxkgBk5NFV3s7cMN/Gf556jSw6jBvV7ca4F9lRL/8cALcZecRibeqU+5dFYqFFmzv5a0Q==" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -6357,9 +6370,9 @@ "dev": true }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz", + "integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==", "dev": true }, "yargs": { diff --git a/package.json b/package.json index 5a89562be..a3ab4aa76 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,8 @@ { "name": "Introduction-to-JavaScript", + "jest": { + "verbose": true + }, "version": "1.0.0", "description": "The module challenge is the afternoon project or assignment that students work through independently. This expands on the guided project completed earlier with the instructor.", "main": "index.js", @@ -24,5 +27,8 @@ "babel-jest": "^26.3.0", "eslint": "^7.10.0", "jest": "^26.4.2" + }, + "dependencies": { + "node": "^15.12.0" } }