getCurrentCart() returns undefined

Hi, when trying to code some logic to generate a sort of ticket that the client could copy and paste (I know it’s a little wierd to need this, but I still need it) the function getCurrentCart() just returns undefined values.
I’ve never coded in javaScript before so it could be that the code is just wrong programed, but I don’t understand why it doesn’t work.

When interacting with the cart I use this function:

function cartN ( type , n ) { //Using a function to read the cart since I don’t know how to do it better
if ( type == “total” ) {
cart . getCurrentCart (). then (( actualCart ) => { cartItem = actualCart.totals });
return cartItem ;
}
if ( type != “total” ) {
cart . getCurrentCart (). then (( actualCart ) => { cartItem = actualCart.lineItems[n ]});
if ( type == “name” ) { return cartItem.name }
if ( type == “price” ) { return cartItem.price }
if ( type == “sku” ) { return cartItem.sku }
if ( type == “num” ) { return cartItem.quantity }
}
Any help?