Click here to Skip to main content
15,920,102 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
 <?php
    function pre_hours(){
    $f = $_POST['pre_hours'];
    return $f;

    }

    function pre_gpa(){
    $f = $_POST['pre_gpa'];
    return $f;

    }


    function pre_sum(){
        $f = pre_gpa() * pre_hours();
        return $f;

    }



    function new_hours(){

    if($_POST['mark1'] == 0 ){
        $hour1 = 0;
    }else{
        $hour1=$_POST['hours1'];}

    if($_POST['mark2'] == 0 ){
        $hour2 = 0;
    }else{
        $hour2=$_POST['hours2'];}

    if($_POST['mark3'] == 0 ){
        $hour3 = 0;
     } else{
        $hour3=$_POST['hours3'];}

    if($_POST['mark4'] == 0 ){
        $hour4 = 0;
     } else{
        $hour4=$_POST['hours4'];}

    if($_POST['mark5'] == 0 ){
        $hour5 = 0;
    }else{
        $hour5=$_POST['hours5'];}

    if($_POST['mark6'] == 0 ){
        $hour6 = 0;
    }else{
        $hour6=$_POST['hours6'];}

    if($_POST['mark7'] == 0 ){
        $hour7 = 0;
    }else{
        $hour7=$_POST['hours7'];}

    if($_POST['mark8'] == 0 ){
        $hour8 = 0;
    }else{
        $hour8=$_POST['hours8'];}



$total = $hour1 + $hour2 + $hour3 + $hour4 + $hour5 + $hour6 + $hour7 + $hour8 ;
    return $total;


    }


    function new_sum(){

    if($_POST['mark1'] == 0 )
        $course1 = 0;
    else{
        $hour1=$_POST['hours1'];
        $course1 = ($_POST['mark1']) * $hour1;
    }



    if($_POST['mark2'] == 0 ){
        $course2 = 0;
    }else{
        $hour2=$_POST['hours2'];
        $course2 = ($_POST['mark2']) * $hour2;
    }



    if($_POST['mark3'] == 0 ){
        $course3 = 0;
    }else{
        $hour3=$_POST['hours3'];
        $course3 = ($_POST['mark3']) * $hour3;
    }



    if($_POST['mark4'] == 0 ){
        $course4 = 0;
    }else{
        $hour4=$_POST['hours4'];
        $course4 = ($_POST['mark4']) * $hour4 ;
    }




    if($_POST['mark5'] == 0 ){
        $course5 = 0;
    }else{


        $hour5=$_POST['hours5'];
        $course5 = ($_POST['mark5']) * $hour5;
    }




    if($_POST['mark6'] == 0 ){
        $course6 = 0;
    }else{
        $hour6=$_POST['hours6'];
        $course6 = ($_POST['mark6']) *$hour6 ;
    }



    if($_POST['mark7'] == 0 ){
        $course7 = 0;
    }else{
        $hour7=$_POST['hours7'];
        $course7=($_POST['mark7'])*$hour7;

    }



    if($_POST['mark8'] == 0 ){
        $course8 = 0;
    }else{
        $hour8=$_POST['hours8'];
        $course8 = ($_POST['mark8']) * $hour8 ;
    }

    $sum = $course1 + $course2 + $course3 + $course4 + $course5 + $course6 + $course7 + $course8;
    return $sum;

    }

    function final_sum(){

        $total = pre_sum()+new_sum();

     if($_POST['mark1'] == 0 ){
        $course1 = 0;
    }else{
        $hour1=$_POST['hours1'];
        $course1 = ($_POST['repeat1']) * $hour1;
    }



    if($_POST['mark2'] == 0 ){
        $course2 = 0;
    }else{
        $hour2=$_POST['hours2'];
        $course2 = ($_POST['repeat2']) * $hour2;
    }



    if($_POST['mark3'] == 0 ){
        $course3 = 0;
    }else{
        $hour3=$_POST['hours3'];
        $course3 = ($_POST['repeat3']) * $hour3;
    }



    if($_POST['mark4'] == 0 ){
        $course4 = 0;
    }else{
        $hour4=$_POST['hours4'];
        $course4 = ($_POST['repeat4']) * $hour4 ;
    }




    if($_POST['mark5'] == 0 ){
        $course5 = 0;
    }else{


        $hour5=$_POST['hours5'];
        $course5 = ($_POST['repeat5']) * $hour5;
    }




    if($_POST['mark6'] == 0 ){
        $course6 = 0;
    }else{
        $hour6=$_POST['hours6'];
        $course6 = ($_POST['repeat6']) *$hour6 ;
    }



    if($_POST['mark7'] == 0 ){
        $course7 = 0;
    }else{
        $hour7=$_POST['hours7'];
        $course7=($_POST['repeat7'])*$hour7;

    }



    if($_POST['mark8'] == 0 ){
        $course8 = 0;
    }else{
        $hour8=$_POST['hours8'];
        $course8 = ($_POST['repeat8']) * $hour8 ;
    }

    $min = $course1 + $course2 + $course3 + $course4 + $course5 + $course6 + $course7 + $course8;
    $final = $total - $min ;
    return $final;

    }


    function final_hours(){


        $total = pre_hours() + new_hours();

     if($_POST['repeat1'] == 0 || $_POST['mark1'] == 0){
        $hour1 = 0;
   } else
        $hour1=$_POST['hours1'];





    if($_POST['repeat2'] == 0 || $_POST['mark2'] == 0 ){
        $hour2 = 0;
    }else{
        $hour2=$_POST['hours2'];

    }



    if($_POST['repeat3'] == 0 || $_POST['mark3'] == 0 ){
        $hour3 = 0;
    }else{
        $hour3=$_POST['hours3'];

    }



    if($_POST['repeat4'] == 0 || $_POST['mark4'] == 0 ){
        $hour4 = 0;
    }else{
        $hour4=$_POST['hours4'];

    }




    if($_POST['repeat5'] == 0 || $_POST['mark5'] == 0 ){
        $hour5 = 0;
    }else{


        $hour5=$_POST['hours5'];

    }




    if($_POST['repeat6'] == 0 || $_POST['mark6'] == 0 ){
        $hour6 = 0;
    }else{
        $hour6=$_POST['hours6'];

    }



    if($_POST['repeat7'] == 0 || $_POST['mark7'] == 0 ){
        $hour7 = 0;
    }else{
        $hour7=$_POST['hours7'];


    }



    if($_POST['repeat8'] == 0 || $_POST['mark8'] == 0 ){
        $hour8 = 0;
    }else{
        $hour8=$_POST['hours8'];

    }{

    $min = $hour1 + $hour2 + $hour3 + $hour4 + $hour5 + $hour6 + $hour7 + $hour8 ;
    $final = $total - $min ;
    return $final;




    }


    function avg(){
        if (new_hours() == 0 ){
            return 0;
         } else{
        $f = new_sum()/new_hours();
        return $f;
        }
    }

    function GPA(){

        if(pre_hours() == 0 || pre_gpa() == 0 )
             return null;


        if (final_hours() ==0 ){
            return 0;
        }else{
        $f = final_sum()/final_hours();
        return $f;
    }}


    ?>


What I have tried:

I need to convert my PHP code to JavaScript, how do I do it? Because I am making an website and I can't use php.i want use js plz
Posted
Updated 28-Jan-21 4:11am
v2
Comments
20212a 28-Jan-21 9:58am    
You just have to write it. There's no magic bullet. Although you could google for a php to javascript converter but I doubt it would even work well, if at all.

This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.

And converting Server side code to Client side? That isn't going to work at all, even if the two languages were identical!

Bite the bullet: sit down, think, design, and then write the code to do the task in JS. It really is the only way.
 
Share this answer
 
You can't. You need to rewrite code. Because PHP is server-side language & Js is client-side language.

But you can use it together. Learn both JavaScript[^] & PHP[^]. Then start doing rewrite.

Here a sample simple website using both Js & PHP
HTML CSS Javascript PHP MySQL To Build A Website - Simple Example[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900