lab-brussels-1 / home

Home repository for Lab Brussels 1.
https://lab-brussels-1.github.io/home
MIT License
4 stars 5 forks source link

Ali: Welcome to JS, 3 weeks #320

Open alihaidermalik20 opened 2 years ago

alihaidermalik20 commented 2 years ago

Learning Objectives

Priorities: πŸ₯š, 🐣, πŸ₯, πŸ” (click to learn more)


There is a lot to learn in this repository. If you can't master all the material at once, that's expected! Anything you don't master now will always be waiting for you to review when you need it. These 4 emoji's will help you prioritize your study time and to measure your progress:


1. What is Programming

What is a program? What is a programming language? How do programs and people fit together?

2. Just Enough JavaScript

Go in depth on JavaScript you need to know for writing interactive text-based programs in the browser. Along the way you will learn how each language feature works in small programs.

3. Understanding Programs

Learn how to understand a larger programs by finding connections between the details and the big picture. By the end of this chapter you will know how to read a new program and do a simple code review.

Priorities: πŸ₯š, 🐣, πŸ₯, πŸ” (click to learn more)


There is a lot to learn in this repository. If you can't master all the material at once, that's expected! Anything you don't master now will always be waiting for you to review when you need it. These 4 emoji's will help you prioritize your study time and to measure your progress:


1. What is Programming

What is a program? What is a programming language? How do programs and people fit together?

2. Just Enough JavaScript

Go in depth on JavaScript you need to know for writing interactive text-based programs in the browser. Along the way you will learn how each language feature works in small programs.

3. Understanding Programs

Learn how to understand a larger programs by finding connections between the details and the big picture. By the end of this chapter you will know how to read a new program and do a simple code review.

Priorities: πŸ₯š, 🐣, πŸ₯, πŸ” (click to learn more)


There is a lot to learn in this repository. If you can't master all the material at once, that's expected! Anything you don't master now will always be waiting for you to review when you need it. These 4 emoji's will help you prioritize your study time and to measure your progress:


1. What is Programming

What is a program? What is a programming language? How do programs and people fit together?

2. Just Enough JavaScript

Go in depth on JavaScript you need to know for writing interactive text-based programs in the browser. Along the way you will learn how each language feature works in small programs.

3. Understanding Programs

Learn how to understand a larger programs by finding connections between the details and the big picture. By the end of this chapter you will know how to read a new program and do a simple code review.

alihaidermalik20 commented 2 years ago

I Need Help With

What went well?

Had prior knowledge of basic of JS

What went less well?

Had to submit my bachelors thesis today so couldn't study as much as i wanted

Sunday Prep Work

Starting to study DOM manipulation

danielhalasz commented 2 years ago

Had to submit my bachelors thesis today so couldn't study as much as i wanted

congratulations!! what is the topic, the title?

Starting to study DOM manipulation

you can wait a bit with that πŸ™‚

alihaidermalik20 commented 2 years ago

Thank you. The title was Sustainable Student Mobility. What's the environmental footprint of outgoing exchange students and what KU Leuven International Office can do to reduce it.

alihaidermalik20 commented 2 years ago

I Need Help With

What went well?

What went less well?

Sunday Prep Work

colevandersWands commented 2 years ago

Since you're already into the DOM you may want to check out the SOC module, and if you want more practice with code challenges you could try BSI.

alihaidermalik20 commented 2 years ago

I Need Help With

What went well?

What went less well?

// only javascript should remain in jumble

let jumble = '3j\n _a__v!,aASs woon c023r\n\t&i pPPPPPPPPPt!!?';

let word = 'javascript';
let jumble2 = '';

for (let i of word) {
    for (let n of jumble) {
        if (i === n){
            jumble2 += jumble.slice(jumble.indexOf(n), jumble.indexOf(n) + 1);
        break;}
}}
console.log(jumble2); 

Sunday Prep Work

danielhalasz commented 2 years ago
  • Couldn't use some array functions with strings such as splice although strings can be considered an array with indexes i thought.

well @alihaidermalik20 , as the name says, array functions are for arrays, not strings :) unless you convert a string to an array first, of course..

  • tried to solve this exercise with Nazgul but couldn't figure out how to keep it in the same variable 'jumble' instead of making a new variable 'jumble2'. Did it in like 3 lines with a regex but then realized the exercise asked to do it with loops.

RegEx are complex and should be avoided for now. the simple solution would be:

"use strict";

let allowed = "arvjstcpi";

let jumble = "3j\n _a__v!,aASs woon c023r\n\t&i pPPPPPPPPPt!!?";

for (let char of jumble) {
  if (allowed.includes(char)) {
    console.log(char);
  }
}
alihaidermalik20 commented 2 years ago
// only javascript should remain in jumble

let jumble = '3j\n _a__v!,aASs woon c023r\n\t&i pPPPPPPPPPt!!?';

// split functions makes the string an array separated by '' quotations

jumble = jumble.split('');

let word = 'javascript';

for (let i = 0; i < jumble.length; i++) {
    let counter = 0;
    let index = jumble[i];

    // checks the current index of jumble against every letter in 'javascript' and makes the counter = 10 
    // if none of the letters match the current index of jumble

    for (let n of word) {
        if (index !== n){
            counter += 1;
            }
}

// if counter is equal to 10 or none of the 10 letters matched the current index, delete that one index and 
// go back one step since the next array/letter in jumble just went one index behind as there's one index less in jumble

if (counter === word.length) {
    jumble.splice(i, 1);
    i -= 1;
} 
}
jumble = jumble.join('');
console.log(jumble);

I was able to solve it without creating another variable with a lot of debugging! There's probably a way to make it much shorter.

alihaidermalik20 commented 2 years ago
"use strict";

let allowed = "arvjstcpi";

let jumble = "3j\n _a__v!,aASs woon c023r\n\t&i pPPPPPPPPPt!!?";

for (let char of jumble) {
  if (allowed.includes(char)) {
    console.log(char);
  }
}

OH! XD Console.logging it instead of having it in the same variable definitely makes it much easier. Didn't realize i could just do that

danielhalasz commented 2 years ago

yeah, not sure we are talking about the same exercise :)

alihaidermalik20 commented 2 years ago
// only javascript should remain in jumble

let jumble = '3j\n _a__v!,aASs woon c023r\n\t&i pPPPPPPPPPt!!?';

let word = 'javascript';

for (let i = 0; i < jumble.length; i++) {
    let counter = 0;
    let index = jumble[i];

    // checks the current index of jumble against every letter in 'javascript' and makes the counter = 10 
    // if none of the letters match the current index of jumble

    for (let n of word) {
        if (index !== n){
            counter += 1;
            }
}

// if counter is equal to 10 or none of the 10 letters matched the current index, delete that one index and 
// go back one step since the next array/letter in jumble just went one index behind as there's one index less in jumble

if (counter === word.length) {
    jumble = jumble.replace(index, '');
    i -= 1;
} 
}
console.log(jumble);

turns out you can skip turning it to array and just use slice function for much shorter code.

danielhalasz commented 2 years ago

which exercise is this?

alihaidermalik20 commented 2 years ago

which exercise is this?

It's the same exercise, i just changed variable allowed = "arvjstcpi" to variable word = 'javascript' and instead of logging it char by char, i changed jumble so only 'javascript'/'arvjstcpi' remains in it and logged jumble.

Perhaps that could be added as another separate exercise where you have to transform jumble variable itself to contain only javascript with loops or regex.

danielhalasz commented 2 years ago

I was referring to this exercise

danielhalasz commented 2 years ago

so you just needed to fill in the blanks

alihaidermalik20 commented 2 years ago

Oh, that was easy. Well it was a good practice anyway πŸ˜†

alihaidermalik20 commented 2 years ago

I did this exercise last week and was wondering if it has clean code or if i should've used a boolean flag instead


console.log('--- begin program ---');

// initializing variables to be used later so that they're local and not global and available under scope in debugging

let input = null;
let checking, output;

while (input===null) {

// first putting the prompt input to checking to check if it meets all the conditions

checking = prompt('Please enter a text starting with a Capital letter and ending with period');

// if nothing is entered in prompt, checking will be an empty string "" and if prompt is cancelled, checking becomes null

if (checking === "" || checking === null) {
    continue;
}
else if (checking[0] !== checking[0].toUpperCase()) {
alert('Please type again, your input did not start with capital letter');

// if you enter this if because first letter is not capital, continue will take you back to while(input===null) line

continue;
} else if (!checking.endsWith('.')) {
alert('Please type again, your input didn\t end with a dot');
continue;
}
else if (checking.length < 2) {
alert('Please type again, you input was less than 2 characters long');
continue;
}
// now that prompt passed all the conditions, you can transfer it to input so the while loop ends
input = checking;
}

// takes input and transforms it to all lowercase first and then cuts off from 0 to last not including 0 but including last character
output = input.toLowerCase().slice(0, -1);
console.log('output:', output);
alert(output);

console.log('--- end program ---');```
danielhalasz commented 2 years ago

it seems fine, though it would benefit from some attention to indentation so it is easier to read.. and some other programming languages are more specific about that..so better to already learn that habit

alihaidermalik20 commented 2 years ago

console.log('--- begin program ---');

// initializing variables to be used later so that they're local and not global and available under scope in debugging

let input = null;
let checking, output;

while (input===null) {

// first putting the prompt input to checking to check if it meets all the conditions

    checking = prompt('Please enter a text starting 
    with a Capital letter and ending with period');

// if nothing is entered in prompt, checking will be an empty string "" and if prompt is cancelled, checking becomes null

    if (checking === "" || checking === null) {
        continue;
    }
    else if (checking[0] !== checking[0].toUpperCase()) {
        alert('Please type again, your input did not 
        start with capital letter');

// if you enter this if because first letter is not capital, continue will take you back to while(input===null) line

        continue;
    } else if (!checking.endsWith('.')) {
        alert('Please type again, your input didn\t 
        end with a dot');
        continue;
    }
    else if (checking.length < 2) {
        alert('Please type again, you input was less 
        than 2 characters long');
        continue;
    }
// now that prompt passed all the conditions, you can transfer it to input so the while loop ends
    input = checking;
}

// takes input and transforms it to all lowercase first and then cuts off from 0 to last not including 0 but including last character
output = input.toLowerCase().slice(0, -1);
console.log('output:', output);
alert(output);

console.log('--- end program ---');```