r/codeHS_Solutions • • Apr 28 '22

I need some help

2 Upvotes

I am trying to write this code but I keep getting a Type Error for my getX values. The code should basically be single player pong.

var ball; var dx = -4; var dy = 4; var rect; var horizontalRect; var verticalRect; var score; var scoreText; var x; var y; var colided; var rect; var rectWidth = 80; var rectHeight = 15; var rectOff = 10; var paused = false;

function start(){ rect = new Rectangle(rectWidth,rectWidth); rect.setPosition(getWidth()/2 - 40, getHeight() - 30); add(rect);

mouseMoveMethod(t);
mouseClickMethod(pause);

setTimer(draw, 20);

}

function draw() { checkElement();

 if (!paused){
     checkWalls();
     ball.move(dx,dy);
 }

}

function pause(e){ paused = !paused; }

function checkElement(){ var elmT = getElementAt(ball.getX(), ball.getY() - 15); var elmB = getElementAt(ball.getX(), ball.getY() + 15); var elmL = getElementAt(ball.getX() - 15, ball.getY()); var elmR = getElementAt(ball.getX() + 15, ball.getY());

if (elmT != null){
    dy = -dy
    if (elmT.getColor() != Color.black){
        remove(elmT);
    }
}
if (elmB != null){
    dy = -dy
    if (elmB.getColor() != Color.black){
        remove(elmB);
    }
}
if (elmL != null){
    dy = -dy
    if (elmL.getColor() != Color.black){
        remove(elmB);
    }
}
if (elmR != null){
    dy = -dy
    if (elmR.getColor() != Color.black){
        remove(elmR);
    }
}

}

function t(e){ rect.setPosition(e.getY() - 40, getHeight() - 20);

}

function forCircle(radius,x,y){ ball = new Circle(20); ball.setPosition(100,100); add(ball);

setTimer(drawCircle, 20);

}

// ball bounces on first contact, moving in a zig zag pattern, unintended, good start function rectBounce(){ if(ball.getX() >= (rect.getX() - ball.getRadius() )){ colided = false; } if(colided) { setTimer(drawBounce, 20) } }

function drawBounce(){ dx = -dy; }

function drawCircle(){ checkWalls(); ball.move(dx,dy); }

function checkWalls(){ if (ball.getX() + ball.getRadius() > getWidth()){ dx = -dx; } if (ball.getX() - ball.getRadius() < 0){ dx = -dx; } if (ball.getY() + ball.getRadius() > getHeight()){ ball.setPosition(getWidth() / 2, getHeight() / 2); }

if (ball.getX() + ball.getRadius() > getWidth()){
        var txt = new Text ("You lose","45pt Arial");
        txt.setPosition(getWidth()/2 - txt.getWidth()/2, 200);
        txt.setColor(Color.blue);
        add(txt);
}

}


r/codeHS_Solutions • • Feb 19 '22

Help with answers for 11.1.2 and 11.1.3

Post image
2 Upvotes

r/codeHS_Solutions • • Feb 17 '22

12.1.4: list of places to travel. (Can somebody help me with This unit pls? I’ve been trying for 2 days now and it won’t work! I’m supposed to create an array of the top 5 places I would like to travel called travelList. Print out the item at index 2. )

Post image
2 Upvotes

r/codeHS_Solutions • • Feb 13 '22

9.1.7 Checkerboard, v2

2 Upvotes

def print_board(board):

for i in range(len(board)):

print(" ".join([str(x) for x in board[i]]))

my_grid = []

count = 1

for i in range(8):

my_grid.append([0] * 8)

for row in range(8):

count = count + 1

for col in range(8):

count = count + 1

if count % 2 == 0:

my_grid[row][col] = 1

print(print_board(my_grid))


r/codeHS_Solutions • • Feb 13 '22

8.3.7: Exclamat!on Po!nts

2 Upvotes

def exclamation(text):

text_list = list(text)

for i in range(len(text_list)):

if text_list[i] == "i":

text_list[i] = "!"

return ("").join(text_list)


r/codeHS_Solutions • • Feb 13 '22

8.3.6: Owls

2 Upvotes

def owl_count(text):

text = text.lower()

count = text.count("owl")

return count


r/codeHS_Solutions • • Oct 17 '21

I really need help on 4.1.4 fix the program please as I have been trying to correct it but still tells me that there is something wrong with your code.

Post image
2 Upvotes

r/codeHS_Solutions • • Jun 01 '21

1.1.5: Short Stack

2 Upvotes

move();

putBall();

putBall();

move();


r/codeHS_Solutions • • Jun 01 '21

1.1.4: Your First Karel Program

2 Upvotes

move();

move();

move();

move();

takeBall();


r/codeHS_Solutions • • Mar 16 '21

2.16.4 HELP

2 Upvotes

Im failing on the one problem plz help

happy=0

happiness=input("Do you want me to draw the face? Yes/No/Other:")

if happiness=="Yes":

happy=happy+5

if happiness=="No":

happy=happy+10

if happy=="Yes":

def YellowHead():

begin_fill()

penup()

setposition(0,-75)

pendown()

color("yellow")

circle(100)

end_fill()

YellowHead()

def Eye():

color("black")

begin_fill()

circle(10)

end_fill()

def Smile():

pensize(10)

right(90)

pendown()

circle(50,180,50)

elif happy=="No":

def HappyFace():

penup()

setposition(-50,50)

for i in range(2):

Eye()

forward(95)

setposition(-50,0)

Smile()

HappyFace()

else:

penup()

forward(300)


r/codeHS_Solutions • • Jan 11 '21

3.8.6 convert to uppercase

2 Upvotes

public void run()

    {

      String end = toUpper("hopethishelps");

      System.out.println(end);

    }

    public String toUpper(String str)

    {

        String out = "";

        int l = str.length();

        for (int i = 0; i < l; i++ )

        {

        char index = str.charAt(i);

        char j = Character.toUpperCase(index);

        String convertedChar = Character.toString(j);

        out += convertedChar;

        }

        return out;

    }


r/codeHS_Solutions • • May 01 '23

Functions capstone

1 Upvotes

var MIN_SPEED = 6;

var canBlock; var goodHands; var runFast; var holdGap; var canTackle;

function start(){ takeInput();

var defensiveLine = whichSide();
if(defensiveLine == true){
    println(" Try out for defensive line. ");
}else{
    println(" Try out for offensive line. ");
}

}

function whichSide(){ var isGood = canTackle && goodHands; var greatPotential = canBlock; return (isGood || greatPotential) && goodHands && runFast <= MIN_SPEED; }

function takeInput(){ canBlock = readBoolean(" Can you block someone? "); goodHands = readBoolean(" Do you have good hand movement? "); runFast = readFloat(" what is your 40 yard dash in seconds? "); holdGap = readBoolean(" Can you hold a gap? "); canTackle = readBoolean(" Can you tackle someone? "); }


r/codeHS_Solutions • • Mar 01 '23

Help Request Can somebody please help me to know what is wrong in here the code works but it says I have everything wrong

Thumbnail
gallery
1 Upvotes

r/codeHS_Solutions • • Mar 01 '23

Solution For anyone stuck on 4.2.4...

1 Upvotes

THIS IS PYTHON BTW

def radius():

for i in range(1):

begin_fill()

color_choice = input ("what colour lol")

color("color_choice")

circle(25)

end_fill()

begin_fill()

color("color_choice")

right(90)

forward(12.5)

left(90)

circle(50)

end_fill()

begin_fill()

color("color_choice")

right(90)

forward(25)

left(90)

circle(75)

end_fill()

begin_fill()

color("color_choice")

right(90)

forward(32.5)

left(90)

circle(100)

end_fill()

radius()


r/codeHS_Solutions • • Nov 22 '22

Need help with 5.3.6 do not know what am doing wrong

Thumbnail
gallery
1 Upvotes

Can anyone let me know what am doing wrong


r/codeHS_Solutions • • Nov 22 '22

I need help with 5.3.6: Girl Scout designation

Thumbnail
gallery
1 Upvotes

Hello, I am having trouble with 5.3.6, I am having issues with this assignment where I have 11/12 requirements but I am missing one. I don’t know what is wrong so this is why I am asking for help.


r/codeHS_Solutions • • Nov 14 '22

Help Request 6.4.8 Most Improved

1 Upvotes

r/codeHS_Solutions • • Oct 11 '22

I need help understanding how to do this please. (C++)

Post image
1 Upvotes

r/codeHS_Solutions • • Oct 04 '22

im very confused

Post image
1 Upvotes

r/codeHS_Solutions • • Sep 09 '22

Help Request I posted here earlier, I’m stuck on this as well.

Post image
1 Upvotes

r/codeHS_Solutions • • Sep 09 '22

Help Request I’m completely stuck! Please help.

Post image
1 Upvotes

r/codeHS_Solutions • • Sep 09 '22

Help Request I usually get these but I’m stuck on how to solve. Please help!

Post image
1 Upvotes

r/codeHS_Solutions • • Sep 08 '22

Help Request 3.8.12: Fixing Grammar. Basic Java.

Thumbnail
gallery
1 Upvotes

r/codeHS_Solutions • • May 24 '22

Solution DM for any Lesson 4 answers

1 Upvotes

just send me what lesson u need for the SQL chapter 4 lessons and I’ll respond in less than an hour


r/codeHS_Solutions • • May 22 '22

12.2.6 The Rectangle Class, Part 4 answer

Post image
1 Upvotes