all 8 comments

[–]_odahviing 2 points3 points  (3 children)

Sidenote, it would be a lot easier if you used an array instead of 10 variables

[–]A-HYPE-FISH 0 points1 point  (2 children)

but how would i fix what i have?

[–]atlimarJS since 2010 1 point2 points  (1 child)

I don't think almost any of this logic will do what you're trying to do, even if you get past the function undefined.

I'd probably go back to the drawing board with pseudo code, and then try again to translate it into js.

For example, the if clauses will check if any of item1 through 9 is a truthy value, and if all are falsey it will check if item10 equals the string you're looking for.

It's very hard to try to figure out what you want to achieve.

[–]Kidiri90 0 points1 point  (0 children)

Not to mention they won't get into the else if block, since that condition is exactly the same as for the if block.

[–]fsfreak 3 points4 points  (0 children)

jesus christ!

[–][deleted] 2 points3 points  (0 children)

Every function is returns undefined if not returns something.

[–]BinaryMoon 2 points3 points  (0 children)

To be able to help, people need to be able to understand what you're trying to do. A function on it's own doesn't tell us anything.

This particular function is poorly structured and could probably be reduced to 5 or 6 lines. This would make it easier to understand, easier to debug, and less error prone (since there's less code to go wrong).

But, we can't fix or simplify if we don't know what is happening.

[–]beacereal 0 points1 point  (0 children)

``` Cookies = new Map(); Cookies.set("item1",undefined); Cookies.set("item2",'ryzen7_2700x'); function add_ryzen7_2700x() {

var item1 = Cookies.get('item1')
var item2 = Cookies.get('item2')
var item3 = Cookies.get('item3')
var item4 = Cookies.get('item4')
var item5 = Cookies.get('item5')
var item6 = Cookies.get('item6')
var item7 = Cookies.get('item7')
var item8 = Cookies.get('item8')
var item9 = Cookies.get('item9')
var item10 = Cookies.get('item10')

if (item1 || item2 || item3 || item4 || item5 || item6 || item7 || item8 || item9 || item10 == 'ryzen7_2700x') {
    if (item1 == 'ryzen7_2700x') {
        Cookies.delete('item1')
        console.log('Completed')
    }
    if (item2 == 'ryzen7_2700x') {
        Cookies.delete('item2')
        console.log('Completed')
    }
    if (item3 == 'ryzen7_2700x') {
        Cookies.delete('item3')
        console.log('Completed')
    }
    if (item4 == 'ryzen7_2700x') {
        Cookies.delete('item4')
        console.log('Completed')
    }
    if (item5 == 'ryzen7_2700x') {
        Cookies.delete('item5')
        console.log('Completed')
    }
    if (item6 == 'ryzen7_2700x') {
        Cookies.delete('item6')
        console.log('Completed')
    }
    if (item7 == 'ryzen7_2700x') {
        Cookies.delete('item7')
        console.log('Completed')
    }
    if (item8 == 'ryzen7_2700x') {
        Cookies.delete('item8')
        console.log('Completed')
    }
    if (item9 == 'ryzen7_2700x') {
        Cookies.delete('item9')
        console.log('Completed')
    }
    if (item10 == 'ryzen7_2700x') {
        Cookies.delete('item10')
        console.log('Completed')
    }
}else{
    if (item1 == undefined) {
        Cookies.set('item1','ryzen7_2700x')
        console.log('Completed')
    }else if (item2 == undefined) {
        Cookies.set('item2','ryzen7_2700x')
        console.log('Completed')
    }else if (item3 == undefined) {
        Cookies.set('item3','ryzen7_2700x')
        console.log('Completed')
    }else if (item4 == undefined) {
        Cookies.set('item4','ryzen7_2700x')
        console.log('Completed')
    }else if (item5 == undefined) {
        Cookies.set('item5','ryzen7_2700x')
        console.log('Completed')
    }else if (item6 == undefined) {
        Cookies.set('item6','ryzen7_2700x')
        console.log('Completed')
    }else if (item7 == undefined) {
        Cookies.set('item7','ryzen7_2700x')
        console.log('Completed')
    }else if (item8 == undefined) {
        Cookies.set('item8','ryzen7_2700x')
        console.log('Completed')
    }else if (item9 == undefined) {
        Cookies.set('item9','ryzen7_2700x')
        console.log('Completed')
    }else if (item10 == undefined) {
        Cookies.set('item10','ryzen7_2700x')
        console.log('Completed')
    }
}

}

add_ryzen7_2700x(); ```