#a problem while learning JavaScriptt

20 messages · Page 1 of 1 (latest)

lucid granite
#

Hello , I took a course to learn JavaScript so im in the syntax , control flow & basic functions so ive done this lecture and I think I got 99% of all infromation thats according that I was develop a little of Lua. there is an practices to just learn this basics and practice so I had an headche with 2 questions and I need help to explain this 2 question and why we write this
// Q1 . Create a for loop that iterates from 0 to 10, but only prints even numbers to the console.

let array_length = numbers.length

for (let i = 0; i < array_length; i++) {
    let current_value = numbers[i]
    let is_even = current_value % 2 === 0
    if (is_even) {
        console.log(current_value)
    }
}```
`// Q2 . Given an array numbers, write a while loop that continues to sum the numbers until the sum is greater than 100, then exits the loop.`
```let array_numbers = [1, 2, 4, 5, 6, 10, 50, 70, 101]
let sum = 0
let i = 0

while (sum < 100) {
    let current_value = array_numbers[i]
    sum = sum + current_value
    i++
    console.log(sum)
}```
livid hazel
#

Lua is a completely different language. Were you learning Javascipt or Lua?

#

If you understood 99% and can't understand this code, either you were studying Lua or they didn't cover these topics.

lucid granite
#

I'm talking that I understand the syntax of JavaScript , control flow and basics easly cause it's simillar of lua in this side .. I understand 60% of this 2 questions but im searching on understanding it fully

livid hazel
lucid granite
#

Q1 I understand it after looking a while at it but question2
why we are putting let sum = 0 and let i = 0
and why when we run it this is the log appear? and what does the i++ doing here specifically i know its an short of i = i+1 but what its job here in this code

livid hazel
#

The i++ increments i by 1.

lucid granite
livid hazel
#

The i is being used as the index of the array. It is incremented to go to the next array element.

livid hazel
lucid granite
#

okay

lucid granite
livid hazel
viscid martenBOT
#

Here is your js(18.15.0) output @livid hazel

NaN
livid hazel
#

/run

let num = 0;
num++;
console.log(num);
viscid martenBOT
#

Here is your js(18.15.0) output @livid hazel

1
lucid granite
#

okay okay I got it , I have another question for you now im new on programming .. the way of become an expert on JavaScript or any other language is just to code and repeat and i will be expert by the time ? and is it okay to feel like untrusting ?

#

untrusting that I didn't got the point even if i got it

livid hazel