Module #4: Principles of Development Flashcards

1
Q

What is jQuery and how do you enable it in your script

A

jQuery is a JavaScript Library.

We load the jQuery library by adding this line of code in the head
section of our HTML page:
< script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js” ></ script >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

write the basic syntax of jQuery.

A

$(selector).action()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the html() method for?

Give writing syntax and reading syntax example.

A

To read or write the text inside the tag, use the jQuery html()
method (A method is an action you can do like adding or deleting an HTML element).

< p id=”tag1” >I am a paragraph</p >

var x = $(“#tag1”) .html(); //reading

$(“#tag1”). mhtml(“hello world”); //writing

now the p display hello world

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is the val() method for?

Give writing syntax and reading syntax example.

A

To read or write the value of the tag, use the jQuery val() method.

< input id=”tag2” type= “text” value=”Old text” >

var x = $(“#tag2”). val(); // Reading
$(“#tag2”). val(“New text”); // Writing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Click event fonction. Understand and give the basic syntax

A

basic: $(). click();

example:

$(“#btn_1”).click( function(){
//something happens here
console. log( “button click!”);
});

Note: this function has no name. For that reason, it is called an anonymous function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is AND, OR, NOT conditions in Javascript?

A

&& : AND Returns a true value if both expressions are true. This operator only evaluates the second expression if necessary.

||: OR Returns a true value if either expression is true. This operator only evaluates the second expression if necessary.

! NOT Reverses the value of the Boolean expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The order of precedence for the logical operators. (AND, OR, NOT)

A
  1. NOT operator
  2. AND operator
  3. OR operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is an array

A

Array is nothing but a collection of elements: the element can be in the format of a string, number,
Boolean, or even an array.
note: number 0 is assigned to first element of the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

find lenght of an array?

A

console. log(var of the array.length)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

sort an array from a to z

A

var of the array. sort()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how do you iterate through an array. give me the formula.

A

var shoppinglist = (penis, graine, fesse)

for (let i = 0 ; i < shoppinglist.length; i++) {console.log(shoppinglist[i] ; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is the order output in an array

when using vararray.sort()

A

number, letter, boulian

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: What is the role of JavaScript in web development?

A

–General-purpose language
–Used to manipulate HTML & CSS in the browser in response to events
–Interacts with HTML & CSS but can be studied separately

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What is the purpose of the developer console and how do you access it?

A

–Used to view output from JavaScript (e.g., console. log())
–Helps debug and inspect web pages
–Access in Chrome:
 –Click the 3-dot icon (top-right)
 –Go to More Tools → Developer Tools
 –Select the Console tab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

where and how to use JS in HTML?
what is the purpuse of use stric?

console.log() utility?
console.clear() utility?
with what must end a statement?

name me 2 type of data and explain them?

A

JavaScript is written inside < script> tags
–”use strict”; enforces variable declarations for cleaner code

–console.log() outputs messages to the developer console
–console.clear() clears the console
–Statements end with ;

–JavaScript supports different data types like strings (“hello”) and numbers (10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: How do you write comments in JavaScript?

A

–Single-line: start with //
  –Example: // This is a comment
–Multi-line: start with /* and end with /
  –Example:
       /
This is    a multi-line    comment */    

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Q: How do you create and use variables in JavaScript?

A

–Create with var (used in this course) or let
–Example: var x; or let y;
–Assign value: x = 5;
–Use in expressions: let z = x + y;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Q: What are the main arithmetic operators in JavaScript?

–Addition:
–Subtraction:
–Multiplication:
–Exponentiation:
–Division:
–Remainder (modulus):

A

Q: What are the main arithmetic operators in JavaScript?
–Addition: a + b
–Subtraction: a - b
–Multiplication: a * b
–Exponentiation: a ** b
–Division: a / b
–Remainder (modulus): a % b → returns the remainder (e.g., 13 % 5 = 3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Q: How does order of precedence affect JavaScript expressions?

A

–Without parentheses: 10 + a / b → division happens first (implicit order)
–With parentheses:
 –10 + (a / b) → forces division before addition
 –(10 + a) / b → forces addition before division
–Different parentheses = different results due to operator precedence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Q: How does JavaScript handle strings and the + operator? (string concatenation)

A

–Strings can use single or double quotes: ‘Fred’ or “Velma”
–+ is used for concatenation (joining strings)
–Example: ‘Shaggy’ + ‘Scooby’ → ‘ShaggyScooby’
–+ in JavaScript works for both math and string concatenation

21
Q

Q: What are the 4 ways to declare variables in JavaScript?

A

–Automatically (not recommended)
–Using var (used in this course)
–Using let (added in 2015)
–Using const (added in 2015)
–var was used from 1995–2015, mostly for older browsers

22
Q

Q: What are the rules for naming variables (identifiers) in JavaScript?

A

–Can include letters, numbers, _, and $
–Cannot start with a number
–Case-sensitive (name ≠ Name)
–Can be any length
–Cannot use reserved words (e.g., var, console)
–Avoid global properties/methods as names
–Examples: subtotal, index_1, taxRate, $log

23
Q

Q: What are camel case and underscore notation in JavaScript? general rules to write var

A

–Camel case: no spaces, capitalize each new word → theCat, theDog
–Underscore notation: use _ to separate words → the_cat, the_dog
–Both styles are acceptable — just stay consistent!

24
Q

Q: What do .length, parseInt(), and .toFixed() do in JavaScript?

A

–string.length: returns number of characters in a string
  → “Shaggy”.length → 6
–parseInt(string): converts a string to an integer
  → parseInt(‘1812’) → 1812
  → parseInt(‘Elephant’) → NaN (not a number)
–number.toFixed(n): formats a number to n decimal places, returns a string
  → 3.14159.toFixed(2) → “3.14”

25
Q

What does the return statement do in JavaScript?

A

–Ends a function and sends back a value
–Used to output a result from a function

26
Q

What is a function in mathematics (and programming)?

A

–A function applies one or more rules to an input to produce an output
–Input: the value you give the function
–Output: the result the function gives back
–We say that f(x) returns the value of y

27
Q

general structure of a fontion

A

general structure

function name(parameter1, parameter2, parameter3) {
// code to be executed
}
For example:
// Function to compute the product of p1 and p2
function myFunction(p1, p2) {
return p1 * p2;
}
JavaScript Functions (w3sc

28
Q

exemple of a fonction

A

function convertToCelcius(degrees_fahrenheit){
var the_answer = (degrees_fahrenheit - 32) * ( 5 / 9 );
return the_answer;
}

29
Q

Q: How do you pause JavaScript code using breakpoints in Chrome DevTools?

A

–Use line-of-code breakpoints

Open the Sources tab

Open the file containing your code

Go to the line you want to pause at

Click the line number → a blue icon will appear
–This lets you debug and inspect your code step-by-step

30
Q

Q: Why use functions in JavaScript?

A

–Break complex problems into smaller parts (divide & conquer)
–Give meaningful names to reusable blocks of code
–Avoid repeating the same code over and over
–Use the same function with different inputs (arguments) to get different results

31
Q

Q: What’s the difference between defining and calling a function in JavaScript?

A

–Defining a function:
 –You create the function using the function keyword
 –Example:

function greet (name) {
return “Hello “ + name;
}
–Calling a function:
 –You run the function by using its name with parentheses
 –Example:

greet(“Carl”);

32
Q

Q: How can you generally tell what the data type of a variable is in JavaScript?

A

–If the value is in quotes, it’s a String
  → ‘Your car is getting ‘ + MPG + ‘ MPG.’ → String
–If the value is the result of math, it’s a Number
  → miles / gas → Number
–If a function returns a value, look at what’s being returned
  → return miles / gas; → returns a Number
  → return ‘Your car is getting ‘ + MPG + ‘ MPG.’; → returns a String

33
Q

Q: What is a Boolean value in JavaScript and how is it used?

A

–A Boolean is always either true or false
–You can assign it directly: var x = true;
–Or use a comparison, which returns a Boolean:
 –a == b returns true if a equals b, else false
–Used in conditions, logic, and control flow

34
Q

Q: What is the general rule for comparing values in JavaScript?

what is the sign for this:
equal to
not equal to
greater than
less then
greater than or equal to
less than or equal to

A

–Use comparison operators to evaluate relationships
–Each comparison returns a Boolean (true or false)
–Key operators:
 –== → equal to
 –!= → not equal to
 –>  → greater than
 –<  → less than
 –>= → greater than or equal to
 –<= → less than or equal to

35
Q

Q: What is the general rule for using if statements in JavaScript?

A

–Use if (condition) to run code only if the condition is true
–The condition uses a comparison (e.g., >=, ==)
–Use = for assignment, not comparison
–Code inside {} only runs if the condition is true
–Always use ; to end each statement

structure = if(condition) { …}

36
Q

Q: What is the general rule and structure for using nested if statements in JavaScript?

A

–Use an if inside another if to check multiple conditions in sequence
–The inner block only runs if the outer condition is true
–Useful for situations with dependent logic (e.g., age AND gender)

General structure:

if (condition1) {
// Code runs if condition1 is true

if (condition2) {
// Code runs if condition1 AND condition2 are true
}
}

37
Q

Q: What is the general rule and structure for using if and else statements in JavaScript?
–Use if to run code only if a condition is true
–Use else to run code when the condition is false
–Allows you to choose between two code blocks

General structure:

if (condition) {
// code runs if condition is true
} else {
// code runs if condition is false
}

A

Q: What is the general rule and structure for using if and else statements in JavaScript?
–Use if to run code only if a condition is true
–Use else to run code when the condition is false
–Allows you to choose between two code blocks

General structure:

if (condition) {
// code runs if condition is true
} else {
// code runs if condition is false
}

38
Q

Q: What is the general rule and structure for using if…else if…else in JavaScript?

A

–Use if…else if…else when you want only one block to run
–JavaScript checks conditions top-down, stops at the first true
–This is called short-circuiting

General structure:

if (condition1) {
// runs if condition1 is true
} else if (condition2) {
// runs if condition1 is false AND condition2 is true
} else {
// runs if none of the above are true
}

39
Q

Q: What is the general rule and structure when using multiple separate if statements?

A

–Each if is independent
–All true conditions run, not just the first one
–This can cause logic errors if conditions overlap

General structure:

if (condition1) {
// runs if condition1 is true
}
if (condition2) {
// also runs if condition2 is true
}

40
Q

: What is the general rule and structure for using isNaN() in JavaScript?

A

–Use isNaN() to check if a value is “Not-a-Number”
–Returns true if the value is not a valid number
–Automatically tries to convert the value to a number before checking

General structure:

isNaN(expression) // returns true or false
Examples:
–isNaN(“123.45”) → false (valid number)
–isNaN(“zebra”) → true (not a number)
–isNaN(0) → false (number)
–isNaN(“$30”) → true (not a number)

41
Q

Q: What is the general rule and structure for validating input using return in a function?

A

–Use if (isNaN(value)) to check for invalid (non-numeric) input
–Use return inside the if block to exit early and skip the rest of the function
–This helps prevent bad data from being processed

General structure:

function someFunction(input) {
if (isNaN(input)) {
return ‘Bad input’;
}

// Continue with the rest of the logic if input is valid
}

42
Q

Q: What is the general rule and structure for using if, else, and else if in JavaScript?

A

–Use if to run code when a condition is true
–Use else to run code when the condition is false
–Use else if to test a new condition if the previous one is false

General structure:

javascript
Copier
Modifier
if (condition1) {
// runs if condition1 is true
} else if (condition2) {
// runs if condition1 is false AND condition2 is true
} else {
// runs if none of the above conditions are true
}

43
Q

Q: What is the general rule and structure for a for loop in JavaScript?

A

–Use a for loop when you want to repeat a block of code a specific number of times
–The loop has three parts:
 1. Initialization (e.g., let i = 0)
 2. Condition (loop runs while this is true)
 3. Increment (e.g., i++ increases the counter)

General structure:

for (initialization; condition; increment) {
// code to repeat
}
Example:

for (var x = 1; x <= 3; x++) {
console.log(x);
}

44
Q

Q: What happens in the computer’s memory during a for loop?

A

–The variable declared in the loop (e.g., x) is stored in memory and updated each time the loop runs
–At the start, the memory holds the initial value (e.g., x = 1)
–Each loop cycle, the value is incremented (e.g., x = 2, then x = 3, etc.)
–Once the loop condition is false, the loop stops and memory stops updating

General structure reminder:

for (var x = 1; x <= 3; x++) {
console.log(x);
}
This explains how x changes from 1 → 2 → 3 → (stops at 4 because x <= 3 becomes false).

45
Q

Q: What happens in computer memory when a for loop is used to calculate a running total?

A

–Use a running total variable (e.g., sumOfNumbers) initialized before the loop
–Inside the loop, update the total using:
sumOfNumbers = sumOfNumbers + counter;
–A loop counter is used to control the number of times this addition happens
–All involved variables (e.g., sumOfNumbers, counter, numberOfLoops) are stored and updated in memory

General structure:

var sum = 0;
for (var i = 1; i <= limit; i++) {
sum = sum + i;
}

46
Q

Q: What is the general rule to calculate future value using a for loop in JavaScript?

A

–Start with an initial value (e.g., futureValue = investment)
–Use a for loop that runs once for each compounding period
–Each loop iteration increases the future value by a percentage of itself
–This is done using:

futureValue += futureValue * annualRate / 100;
Alternative forms:

futureValue = futureValue + (futureValue * (annualRate / 100));
futureValue = futureValue * (1 + (annualRate / 100));
General structure:

var futureValue = startingAmount;
for (var i = 1; i <= years; i++) {
futureValue = futureValue * (1 + rate / 100);
}

47
Q

Q: What is the general rule for using loops to generate repetitive blocks of text in JavaScript?

A

–Use a for loop to repeat code multiple times
–Each iteration outputs a line of text using console.log() or document.write()
–Useful for patterns, menus, repeated instructions, etc.

General structure:

for (var i = 1; i <= numberOfLines; i++) {
console.log(“This is line “ + i);
}

48
Q

Q: What is the general rule for nesting loops in JavaScript?

A

–A loop can be placed inside another loop
–The inner loop runs completely every time the outer loop runs once
–Used to handle rows and columns, tables, or combinations

General structure:

for (var i = 1; i <= outerLimit; i++) {
for (var j = 1; j <= innerLimit; j++) {
console.log(“i = “ + i + “, j = “ + j);
}
}

49
Q

Q: What are loops good for in JavaScript?

A

–Performing calculations that require repetition (e.g., compound interest, sums)
–Generating repetitive content, including HTML elements like:
–< table> rows
–< select> options
–< ul> or < ol> list items
–Often used with conditionals and functions for more complex logic