using the following <!DOCTYPE html> <html lang="en-us"> <head> <meta charset="utf-8">…
- User
using the following
<p class="lead text-dark"> Result = <span id="result"></span> </p> </main> </div>function randomValue(selector) { let value = Math.floor(Math.random() * 10); let element = document.querySelector(selector); element.innerText = value; }
function generateRandomValues() { randomValue("#first-value"); randomValue("#second-value"); }
generateRandomValues(); /* our custom CSS file*/ .card-img-top { width: 100%; max-height: 200px; object-fit: cover; }
.cover-container { max-width: 42em; }
/*
- Header */
.nav-masthead .nav-link { color: rgba(255, 255, 255, .5); border-bottom: .25rem solid transparent; }
.nav-masthead .nav-link:hover, .nav-masthead .nav-link:focus { border-bottom-color: rgba(255, 255, 255, .25); }
.nav-masthead .nav-link + .nav-link { margin-left: 1rem; }
.nav-masthead .active { color: #fff; border-bottom-color: #fff; } Functions are the building blocks of almost everything we will do in the course. At their core functions are collections of statements that allow us to break down more significant problems into smaller ones and will enable us to reuse code. In this exercise, we will use a combination of functions that we create and JavaScript built-in functions to create our “Multiplying Calculator,” which will take two values, multiply them and update the dom with our result. Exercise Step 1 – Create the “getElementValue” function.
- Link your JavaScript file in your HTML, and print a console.log that prints out “javascript calculator linked.”
- Create a function named “getElementValue” that will take one parameter named “selector.”
- The function should return the innerText of the element selected (using the “selector” parameter) a. If you test your element it should look like the output of the following picture. (Note the console.)
- Once you have completed this, you can move on to the next step. Exercise Step 2 – Create a “multiply” function
- Create a function named “multiply” that will take two parameters: “firstValue” and “secondValue”. a. Note when you call this function, you’ll need to pass in numbers, not strings.
- The function will return both numbers multiplied together. If you’re confused about how to do this and want some reference https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Operators/Multiplication. a. Testing your function should look like this. (Note the console)
- Once you have completed this, you can move on to the next step. Exercise Step 3 – Updating the Result in the Dom
- Create a function named “updateResult” that doesn’t take any parameters.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.