Please enable JavaScript.
Coggle requires JavaScript to display documents.
JS M2, USER INPUT, STANDARDS & BEST PRACTICES, NUMBERS & STRING…
JS M2
Functions are key building blocks in JavaScript. They’ll help you make your web pages interactive and dynamic.
-
Statements can be grouped together into code blocks. Curly brackets {} are used to create a code block.
-
A function is a code block that performs a specific task. Use the function keyword followed by a name to create a new function. functiondoSomething()
A function contains the code to perform a task. This code will be executed when the function is called. To call a function use its name followed by parentheses ().
<button onclick = 'myFunction()'>
The code inside a function is executed when the function is called. A function is called by its name
-
Imagine a function named fireworks() contains all required code for the browser to show a colorful animation effect.
Built-in functions are already defined and ready to use. You have already seen (and used) some built-in functions. Ex : console.log et alert
USER INPUT
-
-
-
Web developers can make pages interactive by coding reactions to user inputs.
Select the attribute used to react to a type of user input : onclick
Information provided by the user can be very valuable to your business.
The prompt() function asks the user for an input.
-
prompt() displays a dialog box that asks the user for an input.
You have the option to add text to the dialog box to give the user more precise instructions.
-
-
-
Data submitted by users is frequently stored in a database hosted in a server. The name attribute is required to store data correctly. We’ll simulate what happens in the back-end.
Every submission will generate a new row of data in the table. Run the code and submit the form a couple of times to store data them in the table
The information in a form can be used to make the page interactive and dynamic. In these cases, the button input type is a better choice.
To work with the values from a form, first you need to access the input field. Once you have accessed the input field, you can get the value submitted by the user with .value
-
-
WRITING JS CODE
-
It’s best practice to use camel case when naming variables with more than one word. Camel case uses capitalization to separate words in a variable name. Ex : deviceType
-
Variable names can start and contain letters, underscores (_), or dollar signs ($).
-
-