Slippery tiles?

well im making a game and i want my character to run on some icey tiles and when he stops he will slide a bit, ive tried saying basically if(character is standing on a slippery tile){
if (speed >= 5){
speed = 5;
character.x += speeddirx; //speed = 5
speed -= 0.5;
}
if (speed <= -5){
speed = 5;
character.x += speed
dirx; //speed = -5
speed += 0.5;
} else (speed == 0){
speed = 0;
char.gotoAndStop(“idle”);
}
}

but it doesnt work at all, i know its close, but way off at the same time, so could someone answer this question for me?