# Basic JavaScript 060

31-Use Bracket Notation to Find the First Character in a String

```javascript
// Example
var firstLetterOfFirstName = "";
var firstName = "Ada";

firstLetterOfFirstName = firstName[0];

// Setup
var firstLetterOfLastName = "";
var lastName = "Lovelace";

// Only change code below this line
firstLetterOfLastName = lastName[0];
```

32-Use Bracket Notation to Find the NthtoLast Character in a String

```javascript
// Example
var firstName = "Ada";
var thirdToLastLetterOfFirstName = firstName[firstName.length - 3];

// Setup
var lastName = "Lovelace";

// Only change code below this line
var secondToLastLetterOfLastName = lastName[lastName.length - 2];
```

33-Word Blanks

```javascript
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line
  result = myNoun + " " + myAdjective + " " + myVerb + " " + myAdverb;

  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
```

34-Store Multiple Values in one Variable using JavaScript Arrays

```javascript
// Example
var ourArray = ["John", 23];

// Only change code below this line.
var myArray = ["John", 25];
```

35-Nest one Array within Another Array

```javascript
// Example
var ourArray = [["the universe", 42], ["everything", 101010]];

// Only change code below this line.
var myArray = [["John", "smart"],["Dudao", "stupid"]];
```

36-Access Array Data with Indexes

```javascript
// Example
var ourArray = [1,2,3];
var ourData = ourArray[0]; // equals 1

// Setup
var myArray = [1,2,3];

// Only change code below this line.
var myData = myArray[0];
```

37-Modify Array Data With Indexes

```javascript
// Example
var ourArray = [1,2,3];
ourArray[1] = 3; // ourArray now equals [1,3,3].

// Setup
var myArray = [1,2,3];

// Only change code below this line.

myArray[0] = 3;
```

38-Access MultiDimensional Arrays With Indexes

```javascript
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[2][1];
```

39-Manipulate Arrays With push

```javascript
// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.push(["happy", "joy"]); 
// ourArray now equals ["Stimpson", "J", "cat", ["happy", "joy"]]

// Setup
var myArray = [["John", 23], ["cat", 2]];

// Only change code below this line.
myArray.push(["dog", 3]);
```

40-Manipulate Arrays With pop

```javascript
// Example
var ourArray = [1,2,3];
var removedFromOurArray = ourArray.pop(); 
// removedFromOurArray now equals 3, and ourArray now equals [1,2]

// Setup
var myArray = [["John", 23], ["cat", 2]];

// Only change code below this line.
var removedFromMyArray = myArray.pop();
```

41-Manipulate Arrays With shift

```javascript
// Example
var ourArray = ["Stimpson", "J", ["cat"]];
removedFromOurArray = ourArray.shift();
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].

// Setup
var myArray = [["John", 23], ["dog", 3]];

// Only change code below this line.
var removedFromMyArray = myArray.shift();
```

42-Manipulate Arrays With unshift

```javascript
// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.unshift("Happy"); 
// ourArray now equals ["Happy", "J", "cat"]

// Setup
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();

// Only change code below this line.
myArray.unshift(["Paul", 35]);
```

43-Shopping List

```javascript
var myList = [];

myList = [ ["小米手環", 850], ["入門鋼筆", 39], ["便當", 50], ["皮包", 100], ["鋁箔包飲料", 10] ];
```

44-Write Reusable JavaScript with Functions

* 要 call、調用函數，要將括號 functonName()
* 大括號 curly braces
* 括號 parentheses

```javascript
// Example
function ourReusableFunction() {
  console.log("Heyya, World");
}

ourReusableFunction();

// Only change code below this line
function reusableFunction() {
  console.log("Hi World");
}

reusableFunction();
```

45-Passing Values to Functions with Arguments

* Parameters 形式參數，在 () 中，像是佔位符
* arguments 實際參數，在 {} 中
* <http://meebox.blogspot.tw/2012/07/parameter-argument.html>

```javascript
// Example
function ourFunctionWithArgs(a, b) {
  console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5

// Only change code below this line.
function functionWithArgs(num1, num2){
  console.log(num1 + num2);
}

functionWithArgs(1,2);
functionWithArgs(7,9);
```

46-Global Scope and Functions

* scope 作用域
* 沒用 var 宣告的變數，會自動變成全局 global 變數

```javascript
// Declare your variable here
var myGlobal = 10;

function fun1() {
  // Assign 5 to oopsGlobal Here  
  oopsGlobal = 5;  
}

// Only change code above this line
function fun2() {
  var output = "";
  if (typeof myGlobal != "undefined") {
    output += "myGlobal: " + myGlobal;
  }
  if (typeof oopsGlobal != "undefined") {
    output += " oopsGlobal: " + oopsGlobal;
  }
  console.log(output);
}
```

47-Local Scope and Functions

* 這題的教學有點難懂 =  =

```javascript
function myLocalScope() {
  var myVar = 'use strict';


  console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope

// Now remove the console log line to pass the test
```

48-Global vs Local Scope in Functions

* 優先權

```javascript
// Setup
var outerWear = "T-Shirt";

function myOutfit() {
  // Only change code below this line
  var outerWear = "sweater";


  // Only change code above this line
  return outerWear;
}

myOutfit();
```

49-Return a Value from a Function with Return

```javascript
// Example
function minusSeven(num) {
  return num - 7;
}

// Only change code below this line
function timesFive(num) {
  return num * 5;
}
```

50-Assignment with a Returned Value

* 將 function 返回的值 assign 變數

```javascript
// Example
var changed = 0;

function change(num) {
  return (num + 5) / 3;
}

changed = change(10);

// Setup
var processed = 0;

function processArg(num) {
  return (num + 3) / 5;
}

// Only change code below this line
processed = processArg(7);
```

51-Stand in Line

* 不看 stack overflow 的話看不懂 orz
* 建立一個 `function nextInLine(arr, item){}` 函式，要產生以下的結果
  * nextInLine(\[], 1) should return 1
  * nextInLine(\[2], 1) should return 2
  * nextInLine(\[5,6,7,8,9], 1) should return 5
  * After nextInLine(testArr, 10), testArr\[4] should be 10
* [javascript - Writing a functions that removes an array and adds to the list - Stack Overflow](https://stackoverflow.com/questions/36818668/writing-a-functions-that-removes-an-array-and-adds-to-the-list)

```javascript
function nextInLine(arr, item) {
  // Your code here

  arr.push(item);
  var firstArrNum = arr.shift(); 
  return firstArrNum;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
```

52-Understanding Boolean Values

```javascript
function welcomeToBooleans() {

  // Only change code below this line.

  return true; // Change this line

  // Only change code above this line.
}
```

53-Use Conditional Logic with If Statements

```javascript
// Example
function ourTrueOrFalse(isItTrue) {
  if (isItTrue) { 
    return "Yes, it's true";
  }
  return "No, it's false";
}

// Setup
function trueOrFalse(wasThatTrue) {

  // Only change code below this line.
    if(wasThatTrue){
      return "Yes, that was true";
    }
    return "No, that was false";


  // Only change code above this line.

}

// Change this value to test
trueOrFalse(true);
```

54-Comparison with the Equality Operator

```javascript
// Setup
function testEqual(val) {
  if (val == 12) { // Change this line
    return "Equal";
  }
  return "Not Equal";
}

// Change this value to test
testEqual(10);
```

55-Comparison with the Strict Equality Operator

```javascript
// Setup
function testStrict(val) {
  if (val === 7) { // Change this line
    return "Equal";
  }
  return "Not Equal";
}

// Change this value to test
testStrict(10);
```

56-Comparison with the Inequality Operator

```javascript
// Setup
function testNotEqual(val) {
  if (val != 99) { // Change this line
    return "Not Equal";
  }
  return "Equal";
}

// Change this value to test
testNotEqual(10);
```

57-Comparison with the Strict Inequality Operator

```javascript
// Setup
function testStrictNotEqual(val) {
  // Only Change Code Below this Line

  if (val !== 17) {

  // Only Change Code Above this Line

    return "Not Equal";
  }
  return "Equal";
}

// Change this value to test
testStrictNotEqual(10);
```

58-Comparison with the Greater Than Operator

* the Greater Than Operator 大於符號

```javascript
function testGreaterThan(val) {
  if (val > 100) {  // Change this line
    return "Over 100";
  }

  if (val > 10 ) {  // Change this line
    return "Over 10";
  }

  return "10 or Under";
}

// Change this value to test
testGreaterThan(10);
```

59-Comparison with the Greater Than Or Equal To Operator

```javascript
function testGreaterOrEqual(val) {
  if (val >= 20) {  // Change this line
    return "20 or Over";
  }

  if (val >= 10) {  // Change this line
    return "10 or Over";
  }

  return "9 or Under";
}

// Change this value to test
testGreaterOrEqual(10);
```

60-Comparison with the Less Than Operator

```javascript
function testLessThan(val) {
  if (val <25 ) {  // Change this line
    return "Under 25";
  }

  if (val < 55 ) {  // Change this line
    return "Under 55";
  }

  return "55 or Over";
}

// Change this value to test
testLessThan(10);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ayugioh2003.gitbook.io/free-code-camp-practice/front-end-development-certification/basic-javascript/basic-javascript-60.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
